From d9050efc1d12602daa437f8c3ca58ff18e5744f1 Mon Sep 17 00:00:00 2001 From: Micooz Date: Mon, 2 Jul 2018 15:11:11 +0800 Subject: [PATCH] transports: add "error" event handler for http2 stream --- src/constants.js | 1 + src/transports/h2.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/constants.js b/src/constants.js index 2b4d479..49f9e4f 100644 --- a/src/constants.js +++ b/src/constants.js @@ -19,4 +19,5 @@ export const PROTOCOL_DEFAULT_PORTS = { 'https:': 443, 'ws:': 80, 'wss:': 443, + 'h2:': 443, }; diff --git a/src/transports/h2.js b/src/transports/h2.js index 2948ad2..d39a20c 100644 --- a/src/transports/h2.js +++ b/src/transports/h2.js @@ -18,9 +18,12 @@ export class Http2Inbound extends Inbound { this.onReceive = this.onReceive.bind(this); this.onTimeout = this.onTimeout.bind(this); this.onClose = this.onClose.bind(this); + // stream this._stream = this._conn; - this._session = this._stream.session; this._stream.on('data', this.onReceive); + this._stream.on('error', this.onError); + // session + this._session = this._stream.session; this._session.on('error', this.onError); this._session.on('timeout', this.onTimeout); this._session.on('close', this.onClose); @@ -69,6 +72,10 @@ export class Http2Inbound extends Inbound { this._session.destroy(); this._session = null; } + if (this._stream) { + this._stream.close(); + this._stream = null; + } if (!this._destroyed) { this._destroyed = true; this.emit('close'); @@ -135,6 +142,10 @@ export class Http2Outbound extends Outbound { this._session.destroy(); this._session = null; } + if (this._stream) { + this._stream.close(); + this._stream = null; + } if (!this._destroyed) { this._destroyed = true; this.emit('close');