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.9.2 to 0.10.0-alpha.1

lib/dispatch-controller.js

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

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