| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8eb18e4 commit 9d13337
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -156,6 +156,8 @@ function ClientRequest(options, cb) { | |||
| 156 | 156 | self._flush(); | |
| 157 | 157 | self = null; | |
| 158 | 158 | }); | |
| 159 | + | ||
| 160 | + this._ended = false; | ||
| 159 | 161 | } | |
| 160 | 162 | ||
| 161 | 163 | util.inherits(ClientRequest, OutgoingMessage); | |
@@ -427,6 +429,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) { | |||
| 427 | 429 | ||
| 428 | 430 | // add our listener first, so that we guarantee socket cleanup | |
| 429 | 431 | res.on('end', responseOnEnd); | |
| 432 | + req.on('prefinish', requestOnPrefinish); | ||
| 430 | 433 | var handled = req.emit('response', res); | |
| 431 | 434 | ||
| 432 | 435 | // If the user did not listen for the 'response' event, then they | |
@@ -439,9 +442,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) { | |||
| 439 | 442 | } | |
| 440 | 443 | ||
| 441 | 444 | // client | |
| 442 | - function responseOnEnd() { | ||
| 443 | - var res = this; | ||
| 444 | - var req = res.req; | ||
| 445 | + function responseKeepAlive(res, req) { | ||
| 445 | 446 | var socket = req.socket; | |
| 446 | 447 | ||
| 447 | 448 | if (!req.shouldKeepAlive) { | |
@@ -465,6 +466,26 @@ function responseOnEnd() { | |||
| 465 | 466 | } | |
| 466 | 467 | } | |
| 467 | 468 | ||
| 469 | + function responseOnEnd() { | ||
| 470 | + const res = this; | ||
| 471 | + const req = this.req; | ||
| 472 | + | ||
| 473 | + req._ended = true; | ||
| 474 | + if (!req.shouldKeepAlive || req.finished) | ||
| 475 | + responseKeepAlive(res, req); | ||
| 476 | + } | ||
| 477 | + | ||
| 478 | + function requestOnPrefinish() { | ||
| 479 | + const req = this; | ||
| 480 | + const res = this.res; | ||
| 481 | + | ||
| 482 | + if (!req.shouldKeepAlive) | ||
| 483 | + return; | ||
| 484 | + | ||
| 485 | + if (req._ended) | ||
| 486 | + responseKeepAlive(res, req); | ||
| 487 | + } | ||
| 488 | + | ||
| 468 | 489 | function emitFreeNT(socket) { | |
| 469 | 490 | socket.emit('free'); | |
| 470 | 491 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,38 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const http = require('http'); | ||
| 4 | + | ||
| 5 | + const server = http.createServer((req, res) => { | ||
| 6 | + res.end(); | ||
| 7 | + }).listen(common.PORT, common.mustCall(() => { | ||
| 8 | + const agent = new http.Agent({ | ||
| 9 | + maxSockets: 1, | ||
| 10 | + keepAlive: true | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + const post = http.request({ | ||
| 14 | + agent: agent, | ||
| 15 | + method: 'POST', | ||
| 16 | + port: common.PORT, | ||
| 17 | + }, common.mustCall((res) => { | ||
| 18 | + res.resume(); | ||
| 19 | + })); | ||
| 20 | + | ||
| 21 | + /* What happens here is that the server `end`s the response before we send | ||
| 22 | + * `something`, and the client thought that this is a green light for sending | ||
| 23 | + * next GET request | ||
| 24 | + */ | ||
| 25 | + post.write(Buffer.alloc(16 * 1024, 'X')); | ||
| 26 | + setTimeout(() => { | ||
| 27 | + post.end('something'); | ||
| 28 | + }, 100); | ||
| 29 | + | ||
| 30 | + http.request({ | ||
| 31 | + agent: agent, | ||
| 32 | + method: 'GET', | ||
| 33 | + port: common.PORT, | ||
| 34 | + }, common.mustCall((res) => { | ||
| 35 | + server.close(); | ||
| 36 | + res.connection.end(); | ||
| 37 | + })).end(); | ||
| 38 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments