From 0b7537dd3432dc8f5be3146be585933e41601a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sat, 14 Jul 2018 12:49:14 +0200 Subject: [PATCH 1/3] Revert "http: fix res emit close before user finish" This reverts commit 2a9c83321b7893395d9472755290c31acf4228a4. --- lib/_http_server.js | 6 +----- test/parallel/test-http-req-res-close.js | 15 +++------------ 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/lib/_http_server.js b/lib/_http_server.js index 3d5a1f8f6242f7..425ddef6f954f6 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -562,7 +562,7 @@ function resOnFinish(req, res, socket, state, server) { res.detachSocket(socket); req.emit('close'); - process.nextTick(emitCloseNT, res); + res.emit('close'); if (res._last) { if (typeof socket.destroySoon === 'function') { @@ -585,10 +585,6 @@ function resOnFinish(req, res, socket, state, server) { } } -function emitCloseNT(self) { - self.emit('close'); -} - // The following callback is issued after the headers have been read on a // new message. In this callback we setup the response object and pass it // to the user. diff --git a/test/parallel/test-http-req-res-close.js b/test/parallel/test-http-req-res-close.js index daba55f43427c2..240134cb5d0902 100644 --- a/test/parallel/test-http-req-res-close.js +++ b/test/parallel/test-http-req-res-close.js @@ -2,21 +2,12 @@ const common = require('../common'); const http = require('http'); -const assert = require('assert'); const server = http.Server(common.mustCall((req, res) => { - let resClosed = false; - res.end(); - res.on('finish', common.mustCall(() => { - assert.strictEqual(resClosed, false); - })); - res.on('close', common.mustCall(() => { - resClosed = true; - })); - req.on('close', common.mustCall(() => { - assert.strictEqual(req._readableState.ended, true); - })); + res.on('finish', common.mustCall()); + res.on('close', common.mustCall()); + req.on('close', common.mustCall()); res.socket.on('close', () => server.close()); })); From 174d36d88174bbac54f3643f3018556bb168e014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sat, 14 Jul 2018 12:49:30 +0200 Subject: [PATCH 2/3] Revert "http: always emit close on req and res" This reverts commit 8029a2473e032c5006d2dfc3044bdce1b221dee4. --- lib/_http_server.js | 2 -- test/parallel/test-http-req-res-close.js | 16 ---------------- 2 files changed, 18 deletions(-) delete mode 100644 test/parallel/test-http-req-res-close.js diff --git a/lib/_http_server.js b/lib/_http_server.js index 425ddef6f954f6..8e0cbfbf266878 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -561,8 +561,6 @@ function resOnFinish(req, res, socket, state, server) { req._dump(); res.detachSocket(socket); - req.emit('close'); - res.emit('close'); if (res._last) { if (typeof socket.destroySoon === 'function') { diff --git a/test/parallel/test-http-req-res-close.js b/test/parallel/test-http-req-res-close.js deleted file mode 100644 index 240134cb5d0902..00000000000000 --- a/test/parallel/test-http-req-res-close.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; - -const common = require('../common'); -const http = require('http'); - -const server = http.Server(common.mustCall((req, res) => { - res.end(); - res.on('finish', common.mustCall()); - res.on('close', common.mustCall()); - req.on('close', common.mustCall()); - res.socket.on('close', () => server.close()); -})); - -server.listen(0, common.mustCall(() => { - http.get({ port: server.address().port }, common.mustCall()); -})); From 7f6db652af7df2d5fbccad766242ba7968a1416e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Thu, 19 Jul 2018 09:23:12 +0200 Subject: [PATCH 3/3] Revert "doc: fix HTTP req/res 'close' description" This reverts commit 8ab7ea6eed76d069dfd82684e2157e7d88badebf. --- doc/api/http.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/api/http.md b/doc/api/http.md index fd8bb02776d03f..e83c507bf2ee0a 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -1015,7 +1015,8 @@ interface. This is an [`EventEmitter`][] with the following events: added: v0.6.7 --> -Indicates that the underlying connection was terminated. +Indicates that the underlying connection was terminated before +[`response.end()`][] was called or able to flush. ### Event: 'finish' Indicates that the underlying connection was closed. +Just like `'end'`, this event occurs only once per response. ### message.aborted