http2-proxy
Advanced tools
Comparing version 5.0.3 to 5.0.4
@@ -6,2 +6,2 @@ # 5.0.0 | ||
* 503 error is guaranteed to not have written anything to res. This is useful for proxies which want to be able to retry against other upstream server. | ||
* onRes and onReq can now return a promise (callback is optional in Legacy API). | ||
* onRes and onReq can now return a promise (callback is optional). |
45
index.js
@@ -36,2 +36,3 @@ const net = require('net') | ||
} | ||
// Legacy compat... | ||
promise | ||
@@ -46,2 +47,3 @@ .then(() => callback(null, req, socket, head)) | ||
} | ||
// Legacy compat... | ||
promise | ||
@@ -66,2 +68,3 @@ .then(() => callback(null, req, res)) | ||
// Legacy compat... | ||
if (timeout != null) { | ||
@@ -79,10 +82,19 @@ req.setTimeout(timeout) | ||
if (onReq) { | ||
return new Promise((resolve, reject) => { | ||
const promiseOrReq = onReq(req, options, (err, val) => err ? reject(err) : resolve(val)) | ||
if (promiseOrReq && promiseOrReq.then) { | ||
promiseOrReq.then(resolve).catch(reject) | ||
} else if (promiseOrReq && promiseOrReq.abort) { | ||
resolve(promiseOrReq) | ||
} | ||
}) | ||
if (onReq.length <= 2) { | ||
return onReq(req, options) | ||
} else { | ||
// Legacy compat... | ||
return new Promise((resolve, reject) => { | ||
const promiseOrReq = onReq(req, options, (err, val) => err ? reject(err) : resolve(val)) | ||
if (promiseOrReq) { | ||
if (promiseOrReq.then) { | ||
promiseOrReq.then(resolve).catch(reject) | ||
} else if (promiseOrReq.abort) { | ||
resolve(promiseOrReq) | ||
} else { | ||
throw new Error('onReq must return a promise or a request object') | ||
} | ||
} | ||
}) | ||
} | ||
} else { | ||
@@ -100,9 +112,16 @@ let agent | ||
}, | ||
async (proxyRes, headers) => new Promise((resolve, reject) => { | ||
async (proxyRes, headers) => { | ||
proxyRes.headers = headers | ||
const promise = onRes(req, res, proxyRes, (err, val) => err ? reject(err) : resolve(val)) | ||
if (promise && promise.then) { | ||
promise.then(resolve).catch(reject) | ||
if (onRes.length <= 3) { | ||
return onRes(req, res, proxyRes) | ||
} else { | ||
// Legacy compat... | ||
return new Promise((resolve, reject) => { | ||
const promise = onRes(req, res, proxyRes, (err, val) => err ? reject(err) : resolve(val)) | ||
if (promise && promise.then) { | ||
promise.then(resolve).catch(reject) | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
) | ||
@@ -109,0 +128,0 @@ } |
{ | ||
"name": "http2-proxy", | ||
"version": "5.0.3", | ||
"version": "5.0.4", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "dev": "nodemon --inspect=9308 src", |
@@ -24,6 +24,8 @@ # node-http2-proxy | ||
Request & Response errors are emitted to the server object either as `clientError` for http/1 or `streamError` for http/2. See the NodeJS documentation for further details. | ||
Fully async/await compatible and all callback based usage is optional and discouraged. | ||
You need to use an final and/or error handler since errored responses won't be cleaned up automatically. | ||
Use a final and/or error handler since errored responses won't be cleaned up automatically. This makes it possible to perform retries. | ||
During 503 it is safe to assume that the request never made it to the upstream server. This makes it safe to retry non idempotent methods. | ||
```js | ||
@@ -30,0 +32,0 @@ const finalhandler = require('finalhandler') |
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
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
19323
384
177