undici-thread-interceptor
Advanced tools
Comparing version 0.10.0-alpha.1 to 0.10.0
37
index.js
@@ -107,15 +107,28 @@ 'use strict' | ||
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) | ||
try { | ||
handler.onRequestStart(controller, {}) | ||
if (controller.aborted) { | ||
handler.onResponseError(controller, controller.reason) | ||
return | ||
} | ||
handler.onResponseStart( | ||
controller, | ||
res.statusCode, | ||
res.headers, | ||
res.statusMessage | ||
) | ||
// TODO(mcollina): I don't think this can be triggered, | ||
// but we should consider adding a test for this in the future | ||
/* c8 ignore next 4 */ | ||
if (controller.aborted) { | ||
handler.onResponseError(controller, controller.reason) | ||
return | ||
} | ||
} catch (err) { | ||
handler.onResponseError(controller, err) | ||
return | ||
} | ||
handler.onResponseData(controller, res.rawPayload) | ||
handler.onResponseEnd(controller, []) | ||
}) | ||
@@ -122,0 +135,0 @@ |
@@ -14,3 +14,3 @@ 'use strict' | ||
onResponseStart (controller, statusCode, statusMessage, headers) { | ||
onResponseStart (controller, statusCode, headers, statusMessage) { | ||
const rawHeaders = [] | ||
@@ -37,2 +37,4 @@ for (const [key, val] of Object.entries(headers)) { | ||
// TODO(mcollina): I do not know how to trigger these | ||
/* c8 ignore next 3 */ | ||
onResponseError (controller, err) { | ||
@@ -39,0 +41,0 @@ this.#handler.onError?.(err) |
{ | ||
"name": "undici-thread-interceptor", | ||
"version": "0.10.0-alpha.1", | ||
"version": "0.10.0", | ||
"description": "An Undici interceptor that routes requests over a worker thread", | ||
@@ -30,4 +30,4 @@ "main": "index.js", | ||
"light-my-request": "^6.0.0", | ||
"undici": "7.0.0-alpha.7" | ||
"undici": "^7.0.0" | ||
} | ||
} |
@@ -395,1 +395,21 @@ 'use strict' | ||
}) | ||
test('aborting a request', async (t) => { | ||
const worker = new Worker(join(__dirname, 'fixtures', 'worker1.js')) | ||
t.after(() => worker.terminate()) | ||
const interceptor = createThreadInterceptor({ | ||
domain: '.local', | ||
}) | ||
interceptor.route('myserver', worker) | ||
const abortController = new AbortController() | ||
const agent = new Agent().compose(interceptor) | ||
abortController.abort() | ||
await rejects(request('http://myserver.local', { | ||
dispatcher: agent, | ||
signal: abortController.signal, | ||
})) | ||
}) |
@@ -9,2 +9,3 @@ 'use strict' | ||
const { join } = require('path') | ||
const { setTimeout: sleep } = require('timers/promises') | ||
@@ -51,2 +52,7 @@ const app = fastify() | ||
app.get('/long', async (req, reply) => { | ||
await sleep(1000) | ||
return { hello: 'world' } | ||
}) | ||
wire({ server: app, port: parentPort }) |
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
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
70601
1886
3
+ Addedundici@7.2.0(transitive)
- Removedundici@7.0.0-alpha.7(transitive)
Updatedundici@^7.0.0