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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 var spdy = require('../../lib/spdy'),
     2     Buffer = require('buffer').Buffer;
     4 exports.createSynStream = function(host, url, callback) {
     5   var deflate = spdy.utils.createDeflate(),
     6       chunks = [],
     7       chunksTotal = 0,
     8       syn_stream;
    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);
    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);
    30     var offset = 18;
    31     chunks.forEach(function(chunk) {
    32       chunk.copy(syn_stream, offset);
    33       offset += chunk.length;
    34     });
    36     callback(syn_stream);
    37   });
    38 };

mercurial