| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 33e63fe commit 8403f00
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2073,19 +2073,12 @@ function afterOpen(session, options, headers, streamOptions, err, fd) { | |||
| 2073 | 2073 | headers, streamOptions)); | |
| 2074 | 2074 | } | |
| 2075 | 2075 | ||
| 2076 | - function streamOnError(err) { | ||
| 2077 | - // we swallow the error for parity with HTTP1 | ||
| 2078 | - // all the errors that ends here are not critical for the project | ||
| 2079 | - } | ||
| 2080 | - | ||
| 2081 | - | ||
| 2082 | 2076 | class ServerHttp2Stream extends Http2Stream { | |
| 2083 | 2077 | constructor(session, handle, id, options, headers) { | |
| 2084 | 2078 | super(session, options); | |
| 2085 | 2079 | this[kInit](id, handle); | |
| 2086 | 2080 | this[kProtocol] = headers[HTTP2_HEADER_SCHEME]; | |
| 2087 | 2081 | this[kAuthority] = headers[HTTP2_HEADER_AUTHORITY]; | |
| 2088 | - this.on('error', streamOnError); | ||
| 2089 | 2082 | } | |
| 2090 | 2083 | ||
| 2091 | 2084 | // true if the remote peer accepts push streams | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,15 @@ const server = h2.createServer(); | |||
| 16 | 16 | server.on('stream', common.mustCall((stream) => { | |
| 17 | 17 | stream.respond(); | |
| 18 | 18 | stream.end('ok'); | |
| 19 | + | ||
| 20 | + // the error will be emitted asynchronously | ||
| 21 | + stream.on('error', common.expectsError({ | ||
| 22 | + type: NghttpError, | ||
| 23 | + code: 'ERR_HTTP2_ERROR', | ||
| 24 | + message: 'Stream was already closed or invalid' | ||
| 25 | + })); | ||
| 19 | 26 | }, 2)); | |
| 27 | + | ||
| 20 | 28 | server.on('session', common.mustCall((session) => { | |
| 21 | 29 | session.on('error', common.expectsError({ | |
| 22 | 30 | code: 'ERR_HTTP2_ERROR', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,12 +54,16 @@ const h2 = require('http2'); | |||
| 54 | 54 | ||
| 55 | 55 | const server = h2.createServer(); | |
| 56 | 56 | ||
| 57 | + process.on('uncaughtException', common.mustCall(function(err) { | ||
| 58 | + assert.strictEqual(err.message, 'kaboom no handler'); | ||
| 59 | + })); | ||
| 60 | + | ||
| 57 | 61 | server.on('stream', common.mustCall(function(stream) { | |
| 58 | - // there is no 'error' handler, and this will not crash | ||
| 62 | + // there is no 'error' handler, and this will crash | ||
| 59 | 63 | stream.write('hello'); | |
| 60 | 64 | stream.resume(); | |
| 61 | 65 | ||
| 62 | - expected = new Error('kaboom'); | ||
| 66 | + expected = new Error('kaboom no handler'); | ||
| 63 | 67 | stream.destroy(expected); | |
| 64 | 68 | server.close(); | |
| 65 | 69 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,12 @@ server.on('stream', common.mustCall((stream, headers) => { | |||
| 21 | 21 | }, common.mustCall((err, push, headers) => { | |
| 22 | 22 | assert.strictEqual(push._writableState.ended, true); | |
| 23 | 23 | push.respond(); | |
| 24 | + // cannot write to push() anymore | ||
| 25 | + push.on('error', common.expectsError({ | ||
| 26 | + type: Error, | ||
| 27 | + code: 'ERR_STREAM_WRITE_AFTER_END', | ||
| 28 | + message: 'write after end' | ||
| 29 | + })); | ||
| 24 | 30 | assert(!push.write('test')); | |
| 25 | 31 | stream.end('test'); | |
| 26 | 32 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,14 +18,22 @@ const { | |||
| 18 | 18 | const tests = [ | |
| 19 | 19 | [NGHTTP2_NO_ERROR, false], | |
| 20 | 20 | [NGHTTP2_NO_ERROR, false], | |
| 21 | - [NGHTTP2_PROTOCOL_ERROR, true], | ||
| 21 | + [NGHTTP2_PROTOCOL_ERROR, true, 'NGHTTP2_PROTOCOL_ERROR'], | ||
| 22 | 22 | [NGHTTP2_CANCEL, false], | |
| 23 | - [NGHTTP2_REFUSED_STREAM, true], | ||
| 24 | - [NGHTTP2_INTERNAL_ERROR, true] | ||
| 23 | + [NGHTTP2_REFUSED_STREAM, true, 'NGHTTP2_REFUSED_STREAM'], | ||
| 24 | + [NGHTTP2_INTERNAL_ERROR, true, 'NGHTTP2_INTERNAL_ERROR'] | ||
| 25 | 25 | ]; | |
| 26 | 26 | ||
| 27 | 27 | const server = http2.createServer(); | |
| 28 | 28 | server.on('stream', (stream, headers) => { | |
| 29 | + const test = tests.find((t) => t[0] === Number(headers.rstcode)); | ||
| 30 | + if (test[1]) { | ||
| 31 | + stream.on('error', common.expectsError({ | ||
| 32 | + type: Error, | ||
| 33 | + code: 'ERR_HTTP2_STREAM_ERROR', | ||
| 34 | + message: `Stream closed with error code ${test[2]}` | ||
| 35 | + })); | ||
| 36 | + } | ||
| 29 | 37 | stream.close(headers.rstcode | 0); | |
| 30 | 38 | }); | |
| 31 | 39 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,6 +34,11 @@ server.on('stream', common.mustCall((stream) => { | |||
| 34 | 34 | type: Error | |
| 35 | 35 | } | |
| 36 | 36 | ); | |
| 37 | + stream.on('error', common.expectsError({ | ||
| 38 | + type: Error, | ||
| 39 | + code: 'ERR_STREAM_WRITE_AFTER_END', | ||
| 40 | + message: 'write after end' | ||
| 41 | + })); | ||
| 37 | 42 | assert.strictEqual(stream.write('data'), false); | |
| 38 | 43 | })); | |
| 39 | 44 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments