Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 var fs = require('fs');
2 var path = require('path');
3 var http2 = require('..');
5 http2.globalAgent = new http2.Agent({
6 log: require('../test/util').createLogger('client')
7 });
9 process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
11 // Sending the request
12 // It would be `var request = http2.get(process.argv.pop());` if we wouldn't care about plain mode
13 var options = require('url').parse(process.argv.pop());
14 options.plain = Boolean(process.env.HTTP2_PLAIN);
15 var request = http2.request(options);
16 request.end();
18 // Receiving the response
19 request.on('response', function(response) {
20 response.pipe(process.stdout);
21 response.on('end', finish);
22 });
24 // Receiving push streams
25 request.on('push', function(pushRequest) {
26 var filename = path.join(__dirname, '/push-' + push_count);
27 push_count += 1;
28 console.error('Receiving pushed resource: ' + pushRequest.url + ' -> ' + filename);
29 pushRequest.on('response', function(pushResponse) {
30 pushResponse.pipe(fs.createWriteStream(filename)).on('finish', finish);
31 });
32 });
34 // Quitting after both the response and the associated pushed resources have arrived
35 var push_count = 0;
36 var finished = 0;
37 function finish() {
38 finished += 1;
39 if (finished === (1 + push_count)) {
40 process.exit();
41 }
42 }