| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -445,7 +445,8 @@ function _storeHeader(firstLine, headers) { | |||
| 445 | 445 | } | |
| 446 | 446 | ||
| 447 | 447 | if (!state.contLen && !state.te) { | |
| 448 | - if (!this._hasBody) { | ||
| 448 | + if (!this._hasBody && (this.statusCode === 204 || | ||
| 449 | + this.statusCode === 304)) { | ||
| 449 | 450 | // Make sure we don't end the 0\r\n\r\n at the end of the message. | |
| 450 | 451 | this.chunkedEncoding = false; | |
| 451 | 452 | } else if (!this.useChunkedEncodingByDefault) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,51 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const http = require('http'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const Countdown = require('../common/countdown'); | ||
| 6 | + | ||
| 7 | + // The HEAD:204, GET:200 is the most pathological test case. | ||
| 8 | + // GETs following a 204 response with a content-encoding header failed. | ||
| 9 | + // Responses without bodies and without content-length or encoding caused | ||
| 10 | + // the socket to be closed. | ||
| 11 | + const codes = [204, 200, 200, 304, 200]; | ||
| 12 | + const methods = ['HEAD', 'HEAD', 'GET', 'HEAD', 'GET']; | ||
| 13 | + | ||
| 14 | + const sockets = []; | ||
| 15 | + const agent = new http.Agent(); | ||
| 16 | + agent.maxSockets = 1; | ||
| 17 | + | ||
| 18 | + const countdown = new Countdown(codes.length, () => server.close()); | ||
| 19 | + | ||
| 20 | + const server = http.createServer(common.mustCall((req, res) => { | ||
| 21 | + const code = codes.shift(); | ||
| 22 | + assert.strictEqual(typeof code, 'number'); | ||
| 23 | + assert.ok(code > 0); | ||
| 24 | + res.writeHead(code, {}); | ||
| 25 | + res.end(); | ||
| 26 | + }, codes.length)); | ||
| 27 | + | ||
| 28 | + function nextRequest() { | ||
| 29 | + const request = http.request({ | ||
| 30 | + port: server.address().port, | ||
| 31 | + path: '/', | ||
| 32 | + agent: agent, | ||
| 33 | + method: methods.shift() | ||
| 34 | + }, common.mustCall((response) => { | ||
| 35 | + response.on('end', common.mustCall(() => { | ||
| 36 | + if (countdown.dec()) { | ||
| 37 | + nextRequest(); | ||
| 38 | + } | ||
| 39 | + assert.strictEqual(sockets.length, 1); | ||
| 40 | + })); | ||
| 41 | + response.resume(); | ||
| 42 | + })); | ||
| 43 | + request.on('socket', common.mustCall((socket) => { | ||
| 44 | + if (!sockets.includes(socket)) { | ||
| 45 | + sockets.push(socket); | ||
| 46 | + } | ||
| 47 | + })); | ||
| 48 | + request.end(); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + server.listen(0, common.mustCall(nextRequest)); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments