| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cc37ff2 commit abae61e
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,16 @@ function isRequest(stream) { | |||
| 13 | 13 | return stream.setHeader && typeof stream.abort === 'function'; | |
| 14 | 14 | } | |
| 15 | 15 | ||
| 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 | + | ||
| 16 | 26 | function isReadable(stream) { | |
| 17 | 27 | return typeof stream.readable === 'boolean' || | |
| 18 | 28 | typeof stream.readableEnded === 'boolean' || | |
@@ -72,7 +82,7 @@ function eos(stream, options, callback) { | |||
| 72 | 82 | // TODO (ronag): Improve soft detection to include core modules and | |
| 73 | 83 | // common ecosystem modules that do properly emit 'close' but fail | |
| 74 | 84 | // this generic check. | |
| 75 | - let willEmitClose = ( | ||
| 85 | + let willEmitClose = isServerResponse(stream) || ( | ||
| 76 | 86 | state && | |
| 77 | 87 | state.autoDestroy && | |
| 78 | 88 | state.emitClose && | |
| Original file line number | Diff line number | Diff 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 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments