testing/xpcshell/node-spdy/test/fixtures/frames.js

changeset 1
ca08bd8f51b2
equal deleted inserted replaced
-1:000000000000 0:e8f0d482f642
1 var spdy = require('../../lib/spdy'),
2 Buffer = require('buffer').Buffer;
3
4 exports.createSynStream = function(host, url, callback) {
5 var deflate = spdy.utils.createDeflate(),
6 chunks = [],
7 chunksTotal = 0,
8 syn_stream;
9
10 deflate.on('data', function(chunk) {
11 chunks.push(chunk);
12 chunksTotal += chunk.length;
13 });
14 deflate.write(new Buffer([ 0x00, 0x02, 0x00, 0x04 ]));
15 deflate.write('host');
16 deflate.write(new Buffer([ 0x00, host.length ]));
17 deflate.write(host);
18 deflate.write(new Buffer([ 0x00, 0x03 ]));
19 deflate.write('url');
20 deflate.write(new Buffer([ 0x00, url.length ]));
21 deflate.write(url);
22
23 deflate.flush(function() {
24 syn_stream = new Buffer(18 + chunksTotal);
25 syn_stream.writeUInt32BE(0x80020001, 0);
26 syn_stream.writeUInt32BE(chunksTotal + 8, 4);
27 syn_stream.writeUInt32BE(0x00000001, 8);
28 syn_stream.writeUInt32BE(0x00000000, 12);
29
30 var offset = 18;
31 chunks.forEach(function(chunk) {
32 chunk.copy(syn_stream, offset);
33 offset += chunk.length;
34 });
35
36 callback(syn_stream);
37 });
38 };

mercurial