New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

undici

Package Overview
Dependencies
Maintainers
3
Versions
235
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

undici - npm Package Compare versions

Comparing version 4.11.1 to 4.11.2

6

lib/fetch/body.js

@@ -6,3 +6,3 @@ 'use strict'

const { FormData } = require('./formdata')
const { kState } = require('./symbols')
const { kState, kError } = require('./symbols')
const { Blob } = require('buffer')

@@ -272,2 +272,6 @@ const { kBodyUsed } = require('../core/symbols')

if (stream[kError]) {
throw stream[kError]
}
if (util.isDisturbed(stream)) {

@@ -274,0 +278,0 @@ throw new TypeError('disturbed')

140

lib/fetch/index.js

@@ -34,3 +34,3 @@ // https://github.com/Ethan-Arrowood/undici-fetch

} = require('./util')
const { kState, kHeaders, kGuard, kRealm } = require('./symbols')
const { kState, kHeaders, kGuard, kRealm, kError } = require('./symbols')
const { AbortError } = require('../core/errors')

@@ -86,10 +86,9 @@ const assert = require('assert')

}
this.terminated = { aborted }
if (this.connection) {
this.connection.destroy()
this.connection.destroy(reason)
this.connection = null
}
this.terminated = { aborted }
this.emit('terminated', reason)

@@ -271,4 +270,2 @@ }

function abortFetch (p, request, responseObject) {
const context = this
// 1. Let error be an "AbortError" DOMException.

@@ -297,3 +294,3 @@ const error = new AbortError()

if (response.body != null) {
context.connection.destroy(error)
cancelBody(response.body, error)
}

@@ -656,3 +653,3 @@ }

internalResponse.body = null
context.connection.dump = true
context.dump = true
}

@@ -1343,8 +1340,6 @@

const connection = (context.connection = {
context.connection = {
abort: null,
controller: null,
destroyed: false,
errored: false,
dump: false,
destroy (err) {

@@ -1354,18 +1349,16 @@ if (this.destroyed) {

}
this.destroyed = true
err = err ?? new AbortError()
if (this.abort) {
this.abort()
this.abort(err)
this.abort = null
}
if (err) {
this.errored = err
}
if (this.controller) {
// TODO (fix): Do we need controller here?
if (context.controller) {
try {
this.controller.error(err ?? new AbortError())
this.controller = null
context.controller.error(err)
context.controller = null
} catch (err) {

@@ -1379,3 +1372,3 @@ // Will throw TypeError if body is not readable.

}
})
}

@@ -1516,6 +1509,6 @@ // 1. Let request be fetchParams’s request.

// 1. Let aborted be the termination’s aborted flag.
const aborted = context.terminated.aborted
const aborted = this.terminated.aborted
// 2. If connection uses HTTP/2, then transmit an RST_STREAM frame.
connection.destroy()
this.connection?.destroy()

@@ -1541,3 +1534,3 @@ // 3. If aborted is set, then return an aborted network error.

// the user agent.
const highWaterMark = 65536
const highWaterMark = 64 * 1024 // Same as nodejs fs streams.

@@ -1556,16 +1549,20 @@ // 13. Let sizeAlgorithm be an algorithm that accepts a chunk object

let pullResolve
const stream = new ReadableStream(
{
async start (controller) {
connection.controller = controller
context.controller = controller
},
async pull () {
if (pullAlgorithm) {
pullAlgorithm()
} else {
pullAlgorithm = null
async pull (controller) {
if (!pullAlgorithm) {
await new Promise((resolve) => {
pullResolve = resolve
})
}
await pullAlgorithm(controller)
},
async cancel (reason) {
cancelAlgorithm()
stream[kError] = reason
await cancelAlgorithm(reason)
}

@@ -1600,3 +1597,3 @@ },

// 2. Let aborted be the termination’s aborted flag.
const aborted = context.terminated.aborted
const aborted = this.terminated.aborted

@@ -1609,6 +1606,20 @@ // 3. If aborted is set, then:

// 2. If stream is readable, error stream with an "AbortError" DOMException.
connection.destroy(new AbortError())
try {
this.controller.error(new AbortError())
} catch (err) {
// Will throw TypeError if body is not readable.
if (err.name !== 'TypeError') {
throw err
}
}
} else {
// 4. Otherwise, if stream is readable, error stream with a TypeError.
connection.destroy(new TypeError('terminated'))
try {
this.controller.error(new TypeError('terminated'))
} catch (err) {
// Will throw TypeError if body is not readable.
if (err.name !== 'TypeError') {
throw err
}
}
}

@@ -1618,3 +1629,3 @@

// 6. Otherwise, the user agent should close connection unless it would be bad for performance to do so.
connection.destroy()
this.connection?.destroy()
}

@@ -1638,4 +1649,8 @@

decoder: null,
context,
onConnect (abort) {
// TODO (fix): Do we need connection here?
const { connection } = this.context
if (connection.destroyed) {

@@ -1661,7 +1676,4 @@ abort(new AbortError())

const hasPulled = pullAlgorithm !== undefined
registry.register(stream, this.abort, this)
const body = { stream }
registry.register(body, connection.abort)
response = makeResponse({

@@ -1671,6 +1683,6 @@ status,

headersList: headers[kHeadersList],
body
body: { stream }
})
context.on('terminated', onResponseAborted)
this.context.on('terminated', onResponseAborted)

@@ -1724,3 +1736,3 @@ const codings =

pullAlgorithm = async () => {
pullAlgorithm = async (controller) => {
// 4. Set bytes to the result of handling content codings given

@@ -1741,6 +1753,2 @@ // codings and bytes.

if (!connection.controller) {
return
}
if (bytes === undefined) {

@@ -1753,10 +1761,4 @@ // 2. Otherwise, if the bytes transmission for response’s message

context.off('terminated', onResponseAborted)
context.off('terminated', onRequestAborted)
controller.close()
connection.controller.close()
connection.controller = null
connection.destroy()
return

@@ -1770,3 +1772,3 @@ }

if (bytes instanceof Error) {
context.terminate({ reason: bytes })
this.context.terminate({ reason: bytes })
return

@@ -1776,8 +1778,8 @@ }

// 7. Enqueue a Uint8Array wrapping an ArrayBuffer containing bytes
// into stream.
connection.controller.enqueue(new Uint8Array(bytes))
// into stream.
controller.enqueue(new Uint8Array(bytes))
// 8. If stream is errored, then terminate the ongoing fetch.
if (connection.errored) {
context.terminate({ reason: connection.errored })
if (stream[kError]) {
this.context.terminate({ reason: stream[kError] })
return

@@ -1787,8 +1789,9 @@ }

// 9. If stream doesn’t need more data ask the user agent to suspend
// the ongoing fetch.
return connection.controller.desiredSize > 0
// the ongoing fetch.
return controller.desiredSize > 0
}
if (hasPulled) {
pullAlgorithm()
if (pullResolve) {
pullResolve()
pullResolve = null
}

@@ -1802,3 +1805,3 @@

onData (chunk) {
if (connection.dump) {
if (this.context.dump) {
return

@@ -1825,3 +1828,5 @@ }

async onComplete () {
onComplete () {
registry.unregister(this)
this.decoder.end()

@@ -1831,8 +1836,7 @@ },

onError (error) {
context.off('terminated', onResponseAborted)
context.off('terminated', onRequestAborted)
registry.unregister(this)
connection.destroy(error)
this.decoder?.destroy(error)
context.terminate({ reason: error })
this.context.terminate({ reason: error })

@@ -1839,0 +1843,0 @@ if (!response) {

@@ -9,3 +9,4 @@ 'use strict'

kGuard: Symbol('guard'),
kRealm: Symbol('realm')
kRealm: Symbol('realm'),
kError: Symbol('error')
}
{
"name": "undici",
"version": "4.11.1",
"version": "4.11.2",
"description": "An HTTP/1.1 client, written from scratch for Node.js",

@@ -5,0 +5,0 @@ "homepage": "https://undici.nodejs.org",

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