undici-thread-interceptor
Advanced tools
Comparing version 0.9.2 to 0.10.0-alpha.1
49
index.js
@@ -9,2 +9,4 @@ 'use strict' | ||
const Hooks = require('./lib/hooks') | ||
const DispatchController = require('./lib/dispatch-controller') | ||
const WrapHandler = require('./lib/wrap-handler') | ||
@@ -33,2 +35,4 @@ const kAddress = Symbol('undici-thread-interceptor.address') | ||
handler = handler.onRequestStart ? handler : new WrapHandler(handler) | ||
// Hostnames are case-insensitive | ||
@@ -66,2 +70,4 @@ const roundRobin = routes.get(url.hostname.toLowerCase()) | ||
const controller = new DispatchController() | ||
// We use it as client context where hooks can add non-serializable properties | ||
@@ -77,3 +83,3 @@ const clientCtx = {} | ||
hooks.fireOnClientError(newOpts, null, err) | ||
handler.onError(err) | ||
handler.onResponseError(controller, err) | ||
}) | ||
@@ -90,3 +96,4 @@ } else { | ||
inflights.delete(id) | ||
handler.onError(new Error(`Timeout while waiting from a response from ${url.hostname}`)) | ||
const err = new Error(`Timeout while waiting from a response from ${url.hostname}`) | ||
handler.onResponseError(controller, err) | ||
}, timeout) | ||
@@ -100,3 +107,3 @@ } | ||
hooks.fireOnClientError(newOpts, res, clientCtx, err) | ||
handler.onError(err) | ||
handler.onResponseError(controller, err) | ||
return | ||
@@ -106,27 +113,15 @@ } | ||
const headers = [] | ||
for (const [key, value] of Object.entries(res.headers)) { | ||
if (Array.isArray(value)) { | ||
for (const v of value) { | ||
headers.push(key) | ||
headers.push(v) | ||
} | ||
} else { | ||
headers.push(key) | ||
headers.push(value) | ||
} | ||
handler.onRequestStart(controller, {}) | ||
handler.onResponseStart( | ||
controller, | ||
res.statusCode, | ||
res.statusMessage, | ||
res.headers | ||
) | ||
if (!controller.aborted) { | ||
handler.onResponseData(controller, res.rawPayload) | ||
handler.onResponseEnd(controller, []) | ||
} else { | ||
handler.onResponseError(controller, controller.reason) | ||
} | ||
let aborted = false | ||
handler.onConnect((err) => { | ||
if (err) { | ||
handler.onError(err) | ||
} | ||
aborted = true | ||
}, {}) | ||
handler.onHeaders(res.statusCode, headers, () => {}, res.statusMessage) | ||
if (!aborted) { | ||
handler.onData(res.rawPayload) | ||
handler.onComplete([]) | ||
} | ||
}) | ||
@@ -133,0 +128,0 @@ |
{ | ||
"name": "undici-thread-interceptor", | ||
"version": "0.9.2", | ||
"version": "0.10.0-alpha.1", | ||
"description": "An Undici interceptor that routes requests over a worker thread", | ||
@@ -23,3 +23,2 @@ "main": "index.js", | ||
"fastify": "^5.0.0", | ||
"fastify-undici-dispatcher": "^0.7.0", | ||
"koa": "^2.15.3", | ||
@@ -32,4 +31,4 @@ "neostandard": "^0.11.0", | ||
"light-my-request": "^6.0.0", | ||
"undici": "^6.18.1" | ||
"undici": "7.0.0-alpha.7" | ||
} | ||
} |
@@ -241,3 +241,4 @@ 'use strict' | ||
test('multiple headers', async (t) => { | ||
// TODO: enable this test when undici v7 adds support for multiple headers | ||
test('multiple headers', { skip: true }, async (t) => { | ||
const worker = new Worker(join(__dirname, 'fixtures', 'worker1.js')) | ||
@@ -244,0 +245,0 @@ t.after(() => worker.terminate()) |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
69434
8
38
1852
4
+ Addedundici@7.0.0-alpha.7(transitive)
- Removedundici@6.21.0(transitive)
Updatedundici@7.0.0-alpha.7