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/server.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/server.js')
-rw-r--r-- | testing/xpcshell/node-http2/example/server.js | 67 |
1 files changed, 67 insertions, 0 deletions
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); |