Comparing version 5.1.9 to 5.2.0-beta
45
hiio.js
@@ -219,3 +219,3 @@ 'use strict'; | ||
if (ret.status !== 200) { | ||
if (ret.status < 200 || ret.status > 299) { | ||
return | ||
@@ -313,2 +313,3 @@ } | ||
stream.on('end', () => { | ||
stream.removeAllListeners() | ||
stream.close() | ||
@@ -319,2 +320,3 @@ rv(ret) | ||
stream.on('error', err => { | ||
stream.removeAllListeners() | ||
stream.close() | ||
@@ -326,2 +328,3 @@ ret.error = err | ||
stream.on('frameError', err => { | ||
stream.removeAllListeners() | ||
stream.close() | ||
@@ -361,4 +364,5 @@ ret.error = err | ||
this.keepalive = options.keepalive | ||
this.reconnDelay = options.reconnDelay | ||
this.reconnDelay = options.reconnDelay || 0 | ||
this.connected = false | ||
this.connecting = false | ||
@@ -392,2 +396,3 @@ this.headers = null | ||
this.connected = true | ||
this.connecting = false | ||
}) | ||
@@ -397,2 +402,4 @@ | ||
this.connected = false | ||
this.connecting = false | ||
if (this.keepalive && typeof this.reconn === 'function') { | ||
@@ -416,2 +423,8 @@ if (this.reconnDelay && this.reconnDelay > 0) { | ||
this.session.on('frameError', err => { | ||
this.debug && console.error(err) | ||
this.connected = false | ||
this.session.destroy() | ||
}) | ||
this.session.on('error', err => { | ||
@@ -421,2 +434,14 @@ this.debug && console.error(err) | ||
this.session.destroy() | ||
/** | ||
* 如果没有连接上,再次重连失败会触发error,但是不会触发connect、close,因此,不会继续发起重连。 | ||
* 此处会在错误的时候继续发起重连过程。 | ||
*/ | ||
if (this.keepalive && !this.connected && !this.connecting) { | ||
setTimeout(() => { | ||
if (!this.connected && !this.connecting) { | ||
this.reconn && this.reconn() | ||
} | ||
}, (isNaN(this.reconnDelay) ? 0 : this.reconnDelay) + 100) | ||
} | ||
}) | ||
@@ -555,5 +580,5 @@ } | ||
return { | ||
bodykey : rb, | ||
stream : stm, | ||
ret : ret | ||
bodykey: rb, | ||
stream: stm, | ||
ret: ret | ||
} | ||
@@ -577,3 +602,2 @@ } | ||
return new Promise((rv, rj) => { | ||
stm.on('timeout', () => { | ||
@@ -600,2 +624,3 @@ ret.ok = false | ||
} | ||
stm.removeAllListeners() | ||
stm.close() | ||
@@ -606,2 +631,3 @@ rv(ret) | ||
stm.on('error', err => { | ||
stm.removeAllListeners() | ||
stm.close() | ||
@@ -613,2 +639,3 @@ ret.error = err | ||
stm.on('frameError', err => { | ||
stm.removeAllListeners() | ||
stm.close() | ||
@@ -841,2 +868,3 @@ ret.error = err | ||
req.connected = false | ||
req.connecting = false | ||
req.headers = null | ||
@@ -942,4 +970,8 @@ req.prefix = '' | ||
if (options.keepalive) { | ||
/** | ||
* 重连阶段,如果未能连接,则会导致connect、close事件无法触发。 | ||
*/ | ||
newReq.reconn = () => { | ||
options.sessionRequest = newReq | ||
newReq.connecting = true | ||
this.connect(url, options) | ||
@@ -955,3 +987,2 @@ newReq.init() | ||
hiio.prototype.connectPool = function (url, options = {}) { | ||
if (options.max === undefined || options.max <= 0) { | ||
@@ -958,0 +989,0 @@ options.max = 5 |
@@ -226,12 +226,12 @@ 'use strict' | ||
backend_obj = { | ||
url : tmp.url, | ||
headers : null, | ||
path : tmp.path, | ||
url: tmp.url, | ||
headers: null, | ||
path: tmp.path, | ||
pathLength: tmp.path.length, | ||
rewrite: false, | ||
weight: 1, | ||
weightCount : 0, | ||
alive : true, | ||
reconnDelay : 0, | ||
max: 100, | ||
weightCount: 0, | ||
alive: true, | ||
reconnDelay: 0, | ||
max: 50, | ||
debug: this.debug, | ||
@@ -447,2 +447,4 @@ h2Pool: null, | ||
stm.on('close', () => { | ||
stm.removeAllListeners() | ||
if (stm.rstCode === http2.constants.NGHTTP2_NO_ERROR) { | ||
@@ -449,0 +451,0 @@ if (!resolved && !rejected) { |
{ | ||
"name": "gohttp", | ||
"version": "5.1.9", | ||
"version": "5.2.0-beta", | ||
"description": "http & https client for HTTP/1.1 and HTTP/2", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
113652
2154
3