| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 24abe07 commit 709e368
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -883,17 +883,6 @@ function write_(msg, chunk, encoding, callback, fromEnd) { | |||
| 883 | 883 | err = new ERR_STREAM_DESTROYED('write'); | |
| 884 | 884 | } | |
| 885 | 885 | ||
| 886 | - if (!msg._hasBody) { | ||
| 887 | - if (msg[kRejectNonStandardBodyWrites]) { | ||
| 888 | - throw new ERR_HTTP_BODY_NOT_ALLOWED(); | ||
| 889 | - } else { | ||
| 890 | - debug('This type of response MUST NOT have a body. ' + | ||
| 891 | - 'Ignoring write() calls.'); | ||
| 892 | - process.nextTick(callback); | ||
| 893 | - return true; | ||
| 894 | - } | ||
| 895 | - } | ||
| 896 | - | ||
| 897 | 886 | if (err) { | |
| 898 | 887 | if (!msg.destroyed) { | |
| 899 | 888 | onError(msg, err, callback); | |
@@ -926,6 +915,17 @@ function write_(msg, chunk, encoding, callback, fromEnd) { | |||
| 926 | 915 | msg._implicitHeader(); | |
| 927 | 916 | } | |
| 928 | 917 | ||
| 918 | + if (!msg._hasBody) { | ||
| 919 | + if (msg[kRejectNonStandardBodyWrites]) { | ||
| 920 | + throw new ERR_HTTP_BODY_NOT_ALLOWED(); | ||
| 921 | + } else { | ||
| 922 | + debug('This type of response MUST NOT have a body. ' + | ||
| 923 | + 'Ignoring write() calls.'); | ||
| 924 | + process.nextTick(callback); | ||
| 925 | + return true; | ||
| 926 | + } | ||
| 927 | + } | ||
| 928 | + | ||
| 929 | 929 | if (!fromEnd && msg.socket && !msg.socket.writableCorked) { | |
| 930 | 930 | msg.socket.cork(); | |
| 931 | 931 | process.nextTick(connectionCorkNT, msg.socket); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,27 @@ | |||
| 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 | + })); | ||
| 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 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments