Node.js: returning "this" from writeHead() to allow chaining.
In Node.js version 11.10.0 and later, the writeHead() function returns "this".
This commit is contained in:
@@ -195,6 +195,8 @@ function writeHead(statusCode, reason, obj) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
var fs = require('fs');
|
||||
|
||||
require('unit-http').createServer(function (req, res) {
|
||||
res.writeHead(404, {});
|
||||
res.end(fs.readFileSync('404.html'));
|
||||
res.writeHead(404, {}).end(fs.readFileSync('404.html'));
|
||||
}).listen(7080);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('unit-http').createServer(function (req, res) {
|
||||
res.writeHead(200, {'Content-Length': 12, 'Content-Type': 'text/plain'});
|
||||
res.end('Hello World\n');
|
||||
res.writeHead(200, {'Content-Length': 12, 'Content-Type': 'text/plain'})
|
||||
.end('Hello World\n');
|
||||
}).listen(7080);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('unit-http').createServer(function (req, res) {
|
||||
res.end();
|
||||
res.end();
|
||||
res.end().end();
|
||||
}).listen(7080);
|
||||
|
||||
@@ -6,7 +6,7 @@ require('unit-http').createServer(function (req, res) {
|
||||
body += chunk.toString();
|
||||
});
|
||||
req.on('end', () => {
|
||||
res.writeHead(200, {'Content-Length': Buffer.byteLength(body)});
|
||||
res.end(body);
|
||||
res.writeHead(200, {'Content-Length': Buffer.byteLength(body)})
|
||||
.end(body);
|
||||
});
|
||||
}).listen(7080);
|
||||
|
||||
@@ -6,8 +6,7 @@ require('unit-http').createServer(function (req, res) {
|
||||
res.end();
|
||||
|
||||
if (req.headers['x-write-call']) {
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.write('blah');
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'}).write('blah');
|
||||
}
|
||||
|
||||
Promise.resolve().then(() => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('unit-http').createServer(function (req, res) {
|
||||
res.writeHead(200, 'blah', {'Content-Type': 'text/plain'});
|
||||
res.end();
|
||||
res.writeHead(200, 'blah', {'Content-Type': 'text/plain'}).end();
|
||||
}).listen(7080);
|
||||
|
||||
@@ -14,7 +14,6 @@ require('unit-http').createServer(function (req, res) {
|
||||
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, {});
|
||||
res.end(body);
|
||||
res.writeHead(200, {}).end(body);
|
||||
});
|
||||
}).listen(7080);
|
||||
|
||||
@@ -2,6 +2,5 @@
|
||||
|
||||
require('unit-http').createServer(function (req, res) {
|
||||
res.write('blah');
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.end();
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'}).end();
|
||||
}).listen(7080);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('unit-http').createServer(function (req, res) {
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.end(new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]));
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'})
|
||||
.end(new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]));
|
||||
}).listen(7080);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('unit-http').createServer(function (req, res) {
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.end(res.write('body').toString());
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'})
|
||||
.end(res.write('body').toString());
|
||||
}).listen(7080);
|
||||
|
||||
Reference in New Issue
Block a user