Files
nginx-unit/test/node/variables/app.js
Valentin Bartenev 7fd9444728 Node.js: returning "this" from writeHead() to allow chaining.
In Node.js version 11.10.0 and later, the writeHead() function returns "this".
2019-08-06 16:24:11 +03:00

20 lines
750 B
JavaScript
Executable File

#!/usr/bin/env node
require('unit-http').createServer(function (req, res) {
let body = '';
req.on('data', chunk => {
body += chunk.toString();
});
req.on('end', () => {
res.setHeader('Request-Method', req.method);
res.setHeader('Request-Uri', req.url);
res.setHeader('Server-Protocol', req.httpVersion);
res.setHeader('Request-Raw-Headers', req.rawHeaders.join());
res.setHeader('Content-Length', Buffer.byteLength(body));
res.setHeader('Content-Type', req.headers['content-type']);
res.setHeader('Custom-Header', req.headers['custom-header']);
res.setHeader('Http-Host', req.headers['host']);
res.writeHead(200, {}).end(body);
});
}).listen(7080);