Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup
  • Loading branch information
ronag committed Mar 15, 2020
commit c48885aa10e50c1a2020870b8cae3c9ae562a9eb
8 changes: 4 additions & 4 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,12 @@ function clearIncoming(req) {
if (parser && parser.incoming === req) {
if (req.readableEnded) {
parser.incoming = null;
req.emit('close');
} else {
req.on('end', clearIncoming);
}
} else {
req.emit('close');
}
}

Expand All @@ -678,7 +681,6 @@ function resOnFinish(req, res, socket, state, server) {
assert(state.incoming.length === 0 || state.incoming[0] === req);

state.incoming.shift();
clearIncoming(req);

// If the user never called req.read(), and didn't pipe() or
// .resume() or .on('data'), then we call req._dump() so that the
Expand All @@ -687,9 +689,7 @@ function resOnFinish(req, res, socket, state, server) {
req._dump();

res.detachSocket(socket);
// TODO(ronag): streamify IncomingMessage.destroy()
req._readableState.destroyed = true;
req.emit('close');
clearIncoming(req);
process.nextTick(emitCloseNT, res);

if (res._last) {
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-http-no-read-no-dump.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const common = require('../common');
const http = require('http');
const assert = require('assert');

let onPause = null;

Expand All @@ -11,6 +12,14 @@ const server = http.createServer((req, res) => {
res.writeHead(200);
res.flushHeaders();

let closed = false;
req.on('close', common.mustCall(() => {
closed = true;
}));
req.on('end', common.mustCall(() => {
assert.strictEqual(closed, false);
}));

req.connection.on('pause', () => {
res.end();
onPause();
Expand Down