| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 33a6bf3 commit 334d4f6
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,7 @@ const { | |||
| 32 | 32 | ||
| 33 | 33 | const { getDefaultHighWaterMark } = require('internal/streams/state'); | |
| 34 | 34 | const assert = require('internal/assert'); | |
| 35 | + const EE = require('events'); | ||
| 35 | 36 | const Stream = require('stream'); | |
| 36 | 37 | const internalUtil = require('internal/util'); | |
| 37 | 38 | const { kOutHeaders, utcDate, kNeedDrain } = require('internal/http'); | |
@@ -884,6 +885,11 @@ OutgoingMessage.prototype.pipe = function pipe() { | |||
| 884 | 885 | this.emit('error', new ERR_STREAM_CANNOT_PIPE()); | |
| 885 | 886 | }; | |
| 886 | 887 | ||
| 888 | + OutgoingMessage.prototype[EE.captureRejectionSymbol] = | ||
| 889 | + function(err, event) { | ||
| 890 | + this.destroy(err); | ||
| 891 | + }; | ||
| 892 | + | ||
| 887 | 893 | module.exports = { | |
| 888 | 894 | OutgoingMessage | |
| 889 | 895 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,89 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const events = require('events'); | ||
| 6 | + const { createServer, request } = require('http'); | ||
| 7 | + | ||
| 8 | + events.captureRejections = true; | ||
| 9 | + | ||
| 10 | + { | ||
| 11 | + const server = createServer(common.mustCall((req, res) => { | ||
| 12 | + const _err = new Error('kaboom'); | ||
| 13 | + res.on('drain', common.mustCall(async () => { | ||
| 14 | + throw _err; | ||
| 15 | + })); | ||
| 16 | + | ||
| 17 | + res.socket.on('error', common.mustCall((err) => { | ||
| 18 | + assert.strictEqual(err, _err); | ||
| 19 | + })); | ||
| 20 | + | ||
| 21 | + // Write until there is space in the buffer | ||
| 22 | + while (res.write('hello')) {} | ||
| 23 | + })); | ||
| 24 | + | ||
| 25 | + server.listen(0, common.mustCall(() => { | ||
| 26 | + const req = request({ | ||
| 27 | + method: 'GET', | ||
| 28 | + host: server.address().host, | ||
| 29 | + port: server.address().port | ||
| 30 | + }); | ||
| 31 | + | ||
| 32 | + req.end(); | ||
| 33 | + | ||
| 34 | + req.on('response', common.mustCall((res) => { | ||
| 35 | + res.on('aborted', common.mustCall()); | ||
| 36 | + res.resume(); | ||
| 37 | + server.close(); | ||
| 38 | + })); | ||
| 39 | + })); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + { | ||
| 43 | + let _res; | ||
| 44 | + let shouldEnd = false; | ||
| 45 | + // Not using mustCall here, because it is OS-dependant. | ||
| 46 | + const server = createServer((req, res) => { | ||
| 47 | + // So that we cleanly stop | ||
| 48 | + _res = res; | ||
| 49 | + | ||
| 50 | + if (shouldEnd) { | ||
| 51 | + res.end(); | ||
| 52 | + } | ||
| 53 | + }); | ||
| 54 | + | ||
| 55 | + server.listen(0, common.mustCall(() => { | ||
| 56 | + const _err = new Error('kaboom'); | ||
| 57 | + | ||
| 58 | + const req = request({ | ||
| 59 | + method: 'POST', | ||
| 60 | + host: server.address().host, | ||
| 61 | + port: server.address().port | ||
| 62 | + }); | ||
| 63 | + | ||
| 64 | + req.on('response', common.mustNotCall((res) => { | ||
| 65 | + // So that we cleanly stop | ||
| 66 | + res.resume(); | ||
| 67 | + server.close(); | ||
| 68 | + })); | ||
| 69 | + | ||
| 70 | + req.on('error', common.mustCall((err) => { | ||
| 71 | + server.close(); | ||
| 72 | + // On some variants of Windows, this can happen before | ||
| 73 | + // the server has received the request. | ||
| 74 | + if (_res) { | ||
| 75 | + _res.end(); | ||
| 76 | + } else { | ||
| 77 | + shouldEnd = true; | ||
| 78 | + } | ||
| 79 | + assert.strictEqual(err, _err); | ||
| 80 | + })); | ||
| 81 | + | ||
| 82 | + req.on('drain', common.mustCall(async () => { | ||
| 83 | + throw _err; | ||
| 84 | + })); | ||
| 85 | + | ||
| 86 | + // Write until there is space in the buffer | ||
| 87 | + while (req.write('hello')) {} | ||
| 88 | + })); | ||
| 89 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments