GeezerVison is showing github.com — http: send implicit headers on HEAD with no body · nodejs/node@60ce2bc
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/_http_outgoing.js +11-11Lines changed: 11 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -887,17 +887,6 @@ function write_(msg, chunk, encoding, callback, fromEnd) { | 887 | 887 | err = new ERR_STREAM_DESTROYED('write'); | 888 | 888 | } | 889 | 889 |
| 890 | | - if (!msg._hasBody) { | 891 | | - if (msg[kRejectNonStandardBodyWrites]) { | 892 | | - throw new ERR_HTTP_BODY_NOT_ALLOWED(); | 893 | | - } else { | 894 | | - debug('This type of response MUST NOT have a body. ' + | 895 | | - 'Ignoring write() calls.'); | 896 | | - process.nextTick(callback); | 897 | | - return true; | 898 | | - } | 899 | | - } | 900 | | - | 901 | 890 | if (err) { | 902 | 891 | if (!msg.destroyed) { | 903 | 892 | onError(msg, err, callback); | @@ -930,6 +919,17 @@ function write_(msg, chunk, encoding, callback, fromEnd) { | 930 | 919 | msg._implicitHeader(); | 931 | 920 | } | 932 | 921 |
| | 922 | + if (!msg._hasBody) { | | 923 | + if (msg[kRejectNonStandardBodyWrites]) { | | 924 | + throw new ERR_HTTP_BODY_NOT_ALLOWED(); | | 925 | + } else { | | 926 | + debug('This type of response MUST NOT have a body. ' + | | 927 | + 'Ignoring write() calls.'); | | 928 | + process.nextTick(callback); | | 929 | + return true; | | 930 | + } | | 931 | + } | | 932 | + | 933 | 933 | if (!fromEnd && msg.socket && !msg.socket.writableCorked) { | 934 | 934 | msg.socket.cork(); | 935 | 935 | process.nextTick(connectionCorkNT, msg.socket); | |
Collapse file Copy file name to clipboard +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +const common = require('../common'); | | 3 | +const http = require('http'); | | 4 | + | | 5 | +// This test is to make sure that when the HTTP server | | 6 | +// responds to a HEAD request with data to res.end, | | 7 | +// it does not send any body but the response is sent | | 8 | +// anyway. | | 9 | + | | 10 | +const server = http.createServer(function(req, res) { | | 11 | + res.end('FAIL'); // broken: sends FAIL from hot path. | | 12 | +}); | | 13 | +server.listen(0); | | 14 | + | | 15 | +server.on('listening', common.mustCall(function() { | | 16 | + const req = http.request({ | | 17 | + port: this.address().port, | | 18 | + method: 'HEAD', | | 19 | + path: '/' | | 20 | + }, common.mustCall(function(res) { | | 21 | + res.on('end', common.mustCall(function() { | | 22 | + server.close(); | | 23 | + })); | | 24 | + res.resume(); | | 25 | + })); | | 26 | + req.end(); | | 27 | +})); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-head-response-has-no-body-end.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,7 +29,7 @@ const http = require('http'); | 29 | 29 |
| 30 | 30 | const server = http.createServer(function(req, res) { | 31 | 31 | res.writeHead(200); | 32 | | - res.end(); | | 32 | + res.end('FAIL'); // broken: sends FAIL from hot path. | 33 | 33 | }); | 34 | 34 | server.listen(0); | 35 | 35 |
| |
|