Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

undici-thread-interceptor

Package Overview
Dependencies
Maintainers
8
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

undici-thread-interceptor - npm Package Compare versions

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 })
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc