GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: finished waits for 'close' on OutgoingMessage · nodejs/node@abae61e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/streams
    • end-of-stream.js
  • test/parallel
    • test-http-outgoing-finished.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/end-of-stream.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/end-of-stream.js
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ function isRequest(stream) {
1313
return stream.setHeader && typeof stream.abort === 'function';
1414
}
1515

16+
function isServerResponse(stream) {
17+
return (
18+
typeof stream._sent100 === 'boolean' &&
19+
typeof stream._removedConnection === 'boolean' &&
20+
typeof stream._removedContLen === 'boolean' &&
21+
typeof stream._removedTE === 'boolean' &&
22+
typeof stream._closed === 'boolean'
23+
);
24+
}
25+
1626
function isReadable(stream) {
1727
return typeof stream.readable === 'boolean' ||
1828
typeof stream.readableEnded === 'boolean' ||
@@ -72,7 +82,7 @@ function eos(stream, options, callback) {
7282
// TODO (ronag): Improve soft detection to include core modules and
7383
// common ecosystem modules that do properly emit 'close' but fail
7484
// this generic check.
75-
let willEmitClose = (
85+
let willEmitClose = isServerResponse(stream) || (
7686
state &&
7787
state.autoDestroy &&
7888
state.emitClose &&
Collapse file

‎test/parallel/test-http-outgoing-finished.js‎

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
const common = require('../common');
3+
const { finished } = require('stream');
4+
5+
const http = require('http');
6+
const assert = require('assert');
7+
8+
const server = http.createServer(function(req, res) {
9+
let closed = false;
10+
res
11+
.on('close', common.mustCall(() => {
12+
closed = true;
13+
finished(res, common.mustCall(() => {
14+
server.close();
15+
}));
16+
}))
17+
.end();
18+
finished(res, common.mustCall(() => {
19+
assert.strictEqual(closed, true);
20+
}));
21+
22+
}).listen(0, function() {
23+
http
24+
.request({
25+
port: this.address().port,
26+
method: 'GET'
27+
})
28+
.on('response', function(res) {
29+
res.resume();
30+
})
31+
.end();
32+
});

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.