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');
|
var fs = require('fs');
|
||||||
|
|
||||||
require('unit-http').createServer(function (req, res) {
|
require('unit-http').createServer(function (req, res) {
|
||||||
res.writeHead(404, {});
|
res.writeHead(404, {}).end(fs.readFileSync('404.html'));
|
||||||
res.end(fs.readFileSync('404.html'));
|
|
||||||
}).listen(7080);
|
}).listen(7080);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
require('unit-http').createServer(function (req, res) {
|
require('unit-http').createServer(function (req, res) {
|
||||||
res.writeHead(200, {'Content-Length': 12, 'Content-Type': 'text/plain'});
|
res.writeHead(200, {'Content-Length': 12, 'Content-Type': 'text/plain'})
|
||||||
res.end('Hello World\n');
|
.end('Hello World\n');
|
||||||
}).listen(7080);
|
}).listen(7080);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
require('unit-http').createServer(function (req, res) {
|
require('unit-http').createServer(function (req, res) {
|
||||||
res.end();
|
res.end().end();
|
||||||
res.end();
|
|
||||||
}).listen(7080);
|
}).listen(7080);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ require('unit-http').createServer(function (req, res) {
|
|||||||
body += chunk.toString();
|
body += chunk.toString();
|
||||||
});
|
});
|
||||||
req.on('end', () => {
|
req.on('end', () => {
|
||||||
res.writeHead(200, {'Content-Length': Buffer.byteLength(body)});
|
res.writeHead(200, {'Content-Length': Buffer.byteLength(body)})
|
||||||
res.end(body);
|
.end(body);
|
||||||
});
|
});
|
||||||
}).listen(7080);
|
}).listen(7080);
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ require('unit-http').createServer(function (req, res) {
|
|||||||
res.end();
|
res.end();
|
||||||
|
|
||||||
if (req.headers['x-write-call']) {
|
if (req.headers['x-write-call']) {
|
||||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
res.writeHead(200, {'Content-Type': 'text/plain'}).write('blah');
|
||||||
res.write('blah');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.resolve().then(() => {
|
Promise.resolve().then(() => {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
require('unit-http').createServer(function (req, res) {
|
require('unit-http').createServer(function (req, res) {
|
||||||
res.writeHead(200, 'blah', {'Content-Type': 'text/plain'});
|
res.writeHead(200, 'blah', {'Content-Type': 'text/plain'}).end();
|
||||||
res.end();
|
|
||||||
}).listen(7080);
|
}).listen(7080);
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ require('unit-http').createServer(function (req, res) {
|
|||||||
res.setHeader('Content-Type', req.headers['content-type']);
|
res.setHeader('Content-Type', req.headers['content-type']);
|
||||||
res.setHeader('Custom-Header', req.headers['custom-header']);
|
res.setHeader('Custom-Header', req.headers['custom-header']);
|
||||||
res.setHeader('Http-Host', req.headers['host']);
|
res.setHeader('Http-Host', req.headers['host']);
|
||||||
res.writeHead(200, {});
|
res.writeHead(200, {}).end(body);
|
||||||
res.end(body);
|
|
||||||
});
|
});
|
||||||
}).listen(7080);
|
}).listen(7080);
|
||||||
|
|||||||
@@ -2,6 +2,5 @@
|
|||||||
|
|
||||||
require('unit-http').createServer(function (req, res) {
|
require('unit-http').createServer(function (req, res) {
|
||||||
res.write('blah');
|
res.write('blah');
|
||||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
res.writeHead(200, {'Content-Type': 'text/plain'}).end();
|
||||||
res.end();
|
|
||||||
}).listen(7080);
|
}).listen(7080);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
require('unit-http').createServer(function (req, res) {
|
require('unit-http').createServer(function (req, res) {
|
||||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
res.writeHead(200, {'Content-Type': 'text/plain'})
|
||||||
res.end(new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]));
|
.end(new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]));
|
||||||
}).listen(7080);
|
}).listen(7080);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
require('unit-http').createServer(function (req, res) {
|
require('unit-http').createServer(function (req, res) {
|
||||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
res.writeHead(200, {'Content-Type': 'text/plain'})
|
||||||
res.end(res.write('body').toString());
|
.end(res.write('body').toString());
|
||||||
}).listen(7080);
|
}).listen(7080);
|
||||||
|
|||||||
Reference in New Issue
Block a user