Comparing version 5.0.7 to 5.0.8-beta
'use strict' | ||
const http2 = require('node:http2') | ||
const hiio = require('./hiio.js') | ||
@@ -7,3 +8,2 @@ | ||
let error_502_text = `<!DOCTYPE html><html> | ||
@@ -58,6 +58,6 @@ <head> | ||
let hiiproxy = function (options = {}) { | ||
if (!(this instanceof hiiproxy)) return hiiproxy(options) | ||
let HiiProxy = function (options = {}) { | ||
if (!(this instanceof HiiProxy)) return HiiProxy(options) | ||
if (typeof options !== 'object') options = {} | ||
@@ -124,3 +124,3 @@ | ||
hiiproxy.prototype.fmtConfig = function (cfg, k) { | ||
HiiProxy.prototype.fmtConfig = function (cfg, k) { | ||
if (typeof cfg[k] === 'string') { | ||
@@ -135,3 +135,3 @@ cfg[k] = [ | ||
hiiproxy.prototype.checkConfig = function (tmp, k) { | ||
HiiProxy.prototype.checkConfig = function (tmp, k) { | ||
@@ -177,3 +177,3 @@ if (typeof tmp !== 'object' || (tmp instanceof Array) ) { | ||
hiiproxy.prototype.checkAndSetConfig = function (backend_obj, tmp) { | ||
HiiProxy.prototype.checkAndSetConfig = function (backend_obj, tmp) { | ||
if (tmp.headers && tmp.headers.toString() === '[object Object]') { | ||
@@ -207,3 +207,3 @@ backend_obj.headers = {} | ||
hiiproxy.prototype.setHostProxy = function (cfg) { | ||
HiiProxy.prototype.setHostProxy = function (cfg) { | ||
if (typeof cfg !== 'object') return false | ||
@@ -278,10 +278,9 @@ | ||
} | ||
} //end sub for | ||
} | ||
} //end for | ||
} | ||
hiiproxy.prototype.checkAlive = function (pr) { | ||
HiiProxy.prototype.checkAlive = function (pr) { | ||
if (!pr.h2Pool || !pr.h2Pool.pool[0].connected) { | ||
@@ -294,4 +293,3 @@ return false | ||
hiiproxy.prototype.getBackend = function (c, host) { | ||
HiiProxy.prototype.getBackend = function (c, host) { | ||
let prlist = this.hostProxy[host][c.routepath] | ||
@@ -322,3 +320,2 @@ | ||
} | ||
} | ||
@@ -343,3 +340,3 @@ | ||
hiiproxy.prototype.mid = function () { | ||
HiiProxy.prototype.mid = function () { | ||
let self = this | ||
@@ -366,3 +363,3 @@ | ||
hind -= 1 | ||
hind-- | ||
} | ||
@@ -403,2 +400,3 @@ } | ||
let rpath = pr.rewrite(c, c.headers[':path']) | ||
if (rpath) { | ||
@@ -415,13 +413,22 @@ let path_typ = typeof rpath | ||
await new Promise((rv, rj) => { | ||
let stm = hii.session.request(c.headers) | ||
let resolved = false | ||
let rejected = false | ||
stm.setTimeout(pr.timeout, () => { | ||
stm.close() | ||
stm.close(http2.constants.NGHTTP2_CANCEL) | ||
}) | ||
stm.on('aborted', err => { | ||
rj(err) | ||
!resolved && !rejected && (rejected = true) && rj(err) | ||
}) | ||
stm.on('close', () => { | ||
if (stm.rstCode === http2.constants.NGHTTP2_NO_ERROR) { | ||
!resolved && !rejected && (resolved = true) && rv() | ||
} else { | ||
!resolved && !rejected && (rejected = true) && rj() | ||
} | ||
}) | ||
stm.on('response', (headers, flags) => { | ||
@@ -432,9 +439,9 @@ c.reply.respond(headers) | ||
stm.on('frameError', err => { | ||
stm.close() | ||
rj(err) | ||
stm.close(http2.constants.NGHTTP2_FRAME_SIZE_ERROR) | ||
//!resolved && !rejected && (rejected = true) && rj(err) | ||
}) | ||
stm.on('error', err => { | ||
stm.close() | ||
rj(err) | ||
stm.close(http2.constants.NGHTTP2_INTERNAL_ERROR) | ||
//!resolved && !rejected && (rejected = true) && rj(err) | ||
}) | ||
@@ -456,3 +463,3 @@ | ||
stm.close() | ||
rv(true) | ||
!resolved && !rejected && (resolved = true) && rv() | ||
}) | ||
@@ -464,4 +471,6 @@ | ||
c.send(error_503_text, 503) | ||
} | ||
} finally(() => { | ||
}) | ||
} | ||
@@ -471,4 +480,3 @@ | ||
hiiproxy.prototype.init =function (app) { | ||
HiiProxy.prototype.init =function (app) { | ||
app.config.timeout = this.timeout | ||
@@ -487,2 +495,2 @@ | ||
module.exports = hiiproxy | ||
module.exports = HiiProxy |
{ | ||
"name": "gohttp", | ||
"version": "5.0.7", | ||
"version": "5.0.8-beta", | ||
"description": "http & https client for HTTP/1.1 and HTTP/2", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
110937
2078
2