| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4caf457 commit ca22ce2
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ const { | |||
| 17 | 17 | } = require('internal/errors').codes; | |
| 18 | 18 | ||
| 19 | 19 | function isRequest(stream) { | |
| 20 | - return stream.setHeader && typeof stream.abort === 'function'; | ||
| 20 | + return stream && stream.setHeader && typeof stream.abort === 'function'; | ||
| 21 | 21 | } | |
| 22 | 22 | ||
| 23 | 23 | function destroyer(stream, reading, writing, callback) { | |
@@ -43,22 +43,13 @@ function destroyer(stream, reading, writing, callback) { | |||
| 43 | 43 | ||
| 44 | 44 | // request.destroy just do .end - .abort is what we want | |
| 45 | 45 | if (isRequest(stream)) return stream.abort(); | |
| 46 | - if (typeof stream.destroy === 'function') { | ||
| 47 | - if (stream.req && stream._writableState === undefined) { | ||
| 48 | - // This is a ClientRequest | ||
| 49 | - // TODO(mcollina): backward compatible fix to avoid crashing. | ||
| 50 | - // Possibly remove in a later semver-major change. | ||
| 51 | - stream.req.on('error', noop); | ||
| 52 | - } | ||
| 53 | - return stream.destroy(err); | ||
| 54 | - } | ||
| 46 | + if (isRequest(stream.req)) return stream.req.abort(); | ||
| 47 | + if (typeof stream.destroy === 'function') return stream.destroy(err); | ||
| 55 | 48 | ||
| 56 | 49 | callback(err || new ERR_STREAM_DESTROYED('pipe')); | |
| 57 | 50 | }; | |
| 58 | 51 | } | |
| 59 | 52 | ||
| 60 | - function noop() {} | ||
| 61 | - | ||
| 62 | 53 | function pipe(from, to) { | |
| 63 | 54 | return from.pipe(to); | |
| 64 | 55 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,14 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const common = require('../common'); | |
| 4 | - const { Stream, Writable, Readable, Transform, pipeline } = require('stream'); | ||
| 4 | + const { | ||
| 5 | + Stream, | ||
| 6 | + Writable, | ||
| 7 | + Readable, | ||
| 8 | + Transform, | ||
| 9 | + pipeline, | ||
| 10 | + PassThrough | ||
| 11 | + } = require('stream'); | ||
| 5 | 12 | const assert = require('assert'); | |
| 6 | 13 | const http = require('http'); | |
| 7 | 14 | const { promisify } = require('util'); | |
@@ -483,3 +490,29 @@ const { promisify } = require('util'); | |||
| 483 | 490 | { code: 'ERR_INVALID_CALLBACK' } | |
| 484 | 491 | ); | |
| 485 | 492 | } | |
| 493 | + | ||
| 494 | + { | ||
| 495 | + const server = http.Server(function(req, res) { | ||
| 496 | + res.write('asd'); | ||
| 497 | + }); | ||
| 498 | + server.listen(0, function() { | ||
| 499 | + http.get({ port: this.address().port }, (res) => { | ||
| 500 | + const stream = new PassThrough(); | ||
| 501 | + | ||
| 502 | + stream.on('error', common.mustCall()); | ||
| 503 | + | ||
| 504 | + pipeline( | ||
| 505 | + res, | ||
| 506 | + stream, | ||
| 507 | + common.mustCall((err) => { | ||
| 508 | + assert.ok(err); | ||
| 509 | + // TODO(ronag): | ||
| 510 | + // assert.strictEqual(err.message, 'oh no'); | ||
| 511 | + server.close(); | ||
| 512 | + }) | ||
| 513 | + ); | ||
| 514 | + | ||
| 515 | + stream.destroy(new Error('oh no')); | ||
| 516 | + }).on('error', common.mustNotCall()); | ||
| 517 | + }); | ||
| 518 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments