Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | var spdy = require('../../lib/spdy'), |
michael@0 | 2 | Buffer = require('buffer').Buffer; |
michael@0 | 3 | |
michael@0 | 4 | exports.createSynStream = function(host, url, callback) { |
michael@0 | 5 | var deflate = spdy.utils.createDeflate(), |
michael@0 | 6 | chunks = [], |
michael@0 | 7 | chunksTotal = 0, |
michael@0 | 8 | syn_stream; |
michael@0 | 9 | |
michael@0 | 10 | deflate.on('data', function(chunk) { |
michael@0 | 11 | chunks.push(chunk); |
michael@0 | 12 | chunksTotal += chunk.length; |
michael@0 | 13 | }); |
michael@0 | 14 | deflate.write(new Buffer([ 0x00, 0x02, 0x00, 0x04 ])); |
michael@0 | 15 | deflate.write('host'); |
michael@0 | 16 | deflate.write(new Buffer([ 0x00, host.length ])); |
michael@0 | 17 | deflate.write(host); |
michael@0 | 18 | deflate.write(new Buffer([ 0x00, 0x03 ])); |
michael@0 | 19 | deflate.write('url'); |
michael@0 | 20 | deflate.write(new Buffer([ 0x00, url.length ])); |
michael@0 | 21 | deflate.write(url); |
michael@0 | 22 | |
michael@0 | 23 | deflate.flush(function() { |
michael@0 | 24 | syn_stream = new Buffer(18 + chunksTotal); |
michael@0 | 25 | syn_stream.writeUInt32BE(0x80020001, 0); |
michael@0 | 26 | syn_stream.writeUInt32BE(chunksTotal + 8, 4); |
michael@0 | 27 | syn_stream.writeUInt32BE(0x00000001, 8); |
michael@0 | 28 | syn_stream.writeUInt32BE(0x00000000, 12); |
michael@0 | 29 | |
michael@0 | 30 | var offset = 18; |
michael@0 | 31 | chunks.forEach(function(chunk) { |
michael@0 | 32 | chunk.copy(syn_stream, offset); |
michael@0 | 33 | offset += chunk.length; |
michael@0 | 34 | }); |
michael@0 | 35 | |
michael@0 | 36 | callback(syn_stream); |
michael@0 | 37 | }); |
michael@0 | 38 | }; |