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 | |
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')
-rw-r--r-- | testing/xpcshell/node-http2/example/client.js | 48 | ||||
-rw-r--r-- | testing/xpcshell/node-http2/example/localhost.crt | 14 | ||||
-rw-r--r-- | testing/xpcshell/node-http2/example/localhost.key | 15 | ||||
-rw-r--r-- | testing/xpcshell/node-http2/example/server.js | 67 |
4 files changed, 144 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(); + } +} diff --git a/testing/xpcshell/node-http2/example/localhost.crt b/testing/xpcshell/node-http2/example/localhost.crt new file mode 100644 index 000000000..c4e4d2e96 --- /dev/null +++ b/testing/xpcshell/node-http2/example/localhost.crt @@ -0,0 +1,14 @@ +-----BEGIN CERTIFICATE----- +MIICDTCCAXYCCQC7iiBVXeTv1DANBgkqhkiG9w0BAQUFADBLMQswCQYDVQQGEwJI +VTETMBEGA1UECBMKU29tZS1TdGF0ZTETMBEGA1UEChMKbm9kZS1odHRwMjESMBAG +A1UEAxMJbG9jYWxob3N0MB4XDTE0MTIwMjE4NDcwNFoXDTI0MTEyOTE4NDcwNFow +SzELMAkGA1UEBhMCSFUxEzARBgNVBAgTClNvbWUtU3RhdGUxEzARBgNVBAoTCm5v +ZGUtaHR0cDIxEjAQBgNVBAMTCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOB +jQAwgYkCgYEA8As7rj7xdD+RuAmORju9NI+jtOScGgiAbfovaFyzTu0O0H9SCExi +u6e2iXMRfzomTix/yjRvbdHEXfgONG1MnKUc0oC4GxHXshyMDEXq9LadgAmR/nDL +UVT0eo7KqC21ufaca2nVS9qOdlSCE/p7IJdb2+BF1RmuC9pHpXvFW20CAwEAATAN +BgkqhkiG9w0BAQUFAAOBgQDn8c/9ho9L08dOqEJ2WTBmv4dfRC3oTWR/0oIGsaXb +RhQONy5CJv/ymPYE7nCFWTMaia+w8oFqMie/aNZ7VK6L+hafuUS93IjuTXVN++JP +4948B0BBagvXGTwNtvm/1sZHLrXTkH1dbRUEF8M+KUSRUu2zJgm+e1bD8WTKQOIL +NA== +-----END CERTIFICATE----- diff --git a/testing/xpcshell/node-http2/example/localhost.key b/testing/xpcshell/node-http2/example/localhost.key new file mode 100644 index 000000000..6e1de6264 --- /dev/null +++ b/testing/xpcshell/node-http2/example/localhost.key @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXQIBAAKBgQDwCzuuPvF0P5G4CY5GO700j6O05JwaCIBt+i9oXLNO7Q7Qf1II +TGK7p7aJcxF/OiZOLH/KNG9t0cRd+A40bUycpRzSgLgbEdeyHIwMRer0tp2ACZH+ +cMtRVPR6jsqoLbW59pxradVL2o52VIIT+nsgl1vb4EXVGa4L2kele8VbbQIDAQAB +AoGAKKB+FVup2hb4PsG/RrvNphu5hWA721wdAIAbjfpCjtUocLlb1PO4sjIMfu7u +wy3AVfLKHhsJ0Phz18OoA8+L65NMoMRsHOGaLEnGIJzJcnDLT5+uTFN5di0a1+UK +BzB828rlHBNoQisogVCoKTYlCPJAZuI3trEzupWAV28XjTECQQD5LUEwYq4xr62L +dEq5Qj/+c5paK/jrEBY83VZUmWzYsFgUwmpdku2ITRILQlOM33j6rk8krZZb93sb +38ydmfwjAkEA9p30zyjOI9kKqTl9WdYNYtIXpyNGYa+Pga33o9pawTewiyS2uCYs +wnQQV26bQ0YwQqLQhtIbo4fzCO6Ex0w7LwJBANHNbd8cp4kEX35U+3nDM3i+w477 +CUp6sA6tWrw+tqw4xuEr1T1WshOauP+r6AdsPkPsMo0yb7CdzxVoObPVbLsCQQCc +sx0cjEb/TCeUAy186Z+zzN6umqFb7Jt4wLt7Z4EHCIWqw/c95zPFks3XYDZTdsOv +c5igMdzR+c4ZPMUthWiNAkByx7If12G1Z/R2Y0vIB0WJq4BJnZCZ0mRR0oAmPoA+ +sZbmwctZ3IU+68Rgr4EAhrU04ygjF67IiNyXX0qqu3VH +-----END RSA PRIVATE KEY----- diff --git a/testing/xpcshell/node-http2/example/server.js b/testing/xpcshell/node-http2/example/server.js new file mode 100644 index 000000000..66d8f895d --- /dev/null +++ b/testing/xpcshell/node-http2/example/server.js @@ -0,0 +1,67 @@ +var fs = require('fs'); +var path = require('path'); +var http2 = require('..'); + +// We cache one file to be able to do simple performance tests without waiting for the disk +var cachedFile = fs.readFileSync(path.join(__dirname, './server.js')); +var cachedUrl = '/server.js'; + +// The callback to handle requests +function onRequest(request, response) { + var filename = path.join(__dirname, request.url); + + // Serving server.js from cache. Useful for microbenchmarks. + if (request.url === cachedUrl) { + if (response.push) { + // Also push down the client js, since it's possible if the requester wants + // one, they want both. + var push = response.push('/client.js'); + push.writeHead(200); + fs.createReadStream(path.join(__dirname, '/client.js')).pipe(push); + } + response.end(cachedFile); + } + + // Reading file from disk if it exists and is safe. + else if ((filename.indexOf(__dirname) === 0) && fs.existsSync(filename) && fs.statSync(filename).isFile()) { + response.writeHead(200); + var fileStream = fs.createReadStream(filename); + fileStream.pipe(response); + fileStream.on('finish',response.end); + } + + // Example for testing large (boundary-sized) frames. + else if (request.url === "/largeframe") { + response.writeHead(200); + var body = 'a'; + for (var i = 0; i < 14; i++) { + body += body; + } + body = body + 'a'; + response.end(body); + } + + // Otherwise responding with 404. + else { + response.writeHead(404); + response.end(); + } +} + +// Creating a bunyan logger (optional) +var log = require('../test/util').createLogger('server'); + +// Creating the server in plain or TLS mode (TLS mode is the default) +var server; +if (process.env.HTTP2_PLAIN) { + server = http2.raw.createServer({ + log: log + }, onRequest); +} else { + server = http2.createServer({ + log: log, + key: fs.readFileSync(path.join(__dirname, '/localhost.key')), + cert: fs.readFileSync(path.join(__dirname, '/localhost.crt')) + }, onRequest); +} +server.listen(process.env.HTTP2_PORT || 8080); |