diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/xpcshell/node-http2/example/client.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/xpcshell/node-http2/example/client.js')
-rw-r--r-- | testing/xpcshell/node-http2/example/client.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/testing/xpcshell/node-http2/example/client.js b/testing/xpcshell/node-http2/example/client.js new file mode 100644 index 000000000..75a4bc011 --- /dev/null +++ b/testing/xpcshell/node-http2/example/client.js @@ -0,0 +1,48 @@ +var fs = require('fs'); +var path = require('path'); +var http2 = require('..'); +var urlParse = require('url').parse; + +// Setting the global logger (optional) +http2.globalAgent = new http2.Agent({ + rejectUnauthorized: true, + log: require('../test/util').createLogger('client') +}); + +// Sending the request +var url = process.argv.pop(); +var options = urlParse(url); + +// Optionally verify self-signed certificates. +if (options.hostname == 'localhost') { + options.key = fs.readFileSync(path.join(__dirname, '/localhost.key')); + options.ca = fs.readFileSync(path.join(__dirname, '/localhost.crt')); +} + +var request = process.env.HTTP2_PLAIN ? http2.raw.get(options) : http2.get(options); + +// Receiving the response +request.on('response', function(response) { + response.pipe(process.stdout); + response.on('end', finish); +}); + +// Receiving push streams +request.on('push', function(pushRequest) { + var filename = path.join(__dirname, '/push-' + push_count); + push_count += 1; + console.error('Receiving pushed resource: ' + pushRequest.url + ' -> ' + filename); + pushRequest.on('response', function(pushResponse) { + pushResponse.pipe(fs.createWriteStream(filename)).on('finish', finish); + }); +}); + +// Quitting after both the response and the associated pushed resources have arrived +var push_count = 0; +var finished = 0; +function finish() { + finished += 1; + if (finished === (1 + push_count)) { + process.exit(); + } +} |