Socket
Socket
Sign inDemoInstall

undici

Package Overview
Dependencies
1
Maintainers
2
Versions
205
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

23

lib/client-base.js

@@ -187,4 +187,5 @@ 'use strict'

let request
try {
this[kQueue].push(new Request(opts, callback))
request = new Request(opts, callback)
} catch (err) {

@@ -195,2 +196,4 @@ process.nextTick(callback, err, null)

this[kQueue].push(request)
if (!this[kSocket] && !this[kRetryTimeout]) {

@@ -201,2 +204,4 @@ connect(this)

resume(this)
return request
}

@@ -552,10 +557,2 @@

if (!client.connected) {
return
}
if (client[kWriting]) {
return
}
const request = client[kQueue][client[kPendingIdx]]

@@ -570,2 +567,10 @@

if (!client.connected) {
return
}
if (client[kWriting]) {
return
}
if (!request.idempotent && client.running) {

@@ -572,0 +577,0 @@ // Non-idempotent request cannot be retried.

@@ -19,2 +19,4 @@ const {

function nop () {}
class Client extends ClientBase {

@@ -89,2 +91,6 @@ request (opts, callback) {

pipeline (opts, handler) {
if (!opts || typeof opts !== 'object') {
return new PassThrough().destroy(new InvalidArgumentError('invalid opts'))
}
if (typeof handler !== 'function') {

@@ -160,3 +166,3 @@ return new PassThrough().destroy(new InvalidArgumentError('invalid handler'))

this[kEnqueue](opts, function (err, data) {
const request = this[kEnqueue](opts, function (err, data) {
if (err) {

@@ -194,5 +200,2 @@ if (!ret.destroyed) {

// TODO: Should this somehow be wrapped earlier?
ret.destroy = this.wrap(ret, ret.destroy)
try {

@@ -206,2 +209,3 @@ body = handler({

} catch (err) {
res.on('error', nop)
if (!ret.destroyed) {

@@ -257,2 +261,4 @@ ret.destroy(err)

ret.destroy = request.wrap(ret, ret.destroy)
return ret

@@ -259,0 +265,0 @@ }

@@ -120,2 +120,8 @@ 'use strict'

if (this.streaming) {
this.body.on('error', (err) => {
this.invoke(err, null)
})
}
{

@@ -122,0 +128,0 @@ // TODO (perf): Build directy into buffer instead of

{
"name": "undici",
"version": "1.0.0",
"version": "1.0.1",
"description": "An HTTP/1.1 client, written from scratch for Node.js",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -130,2 +130,3 @@ # undici

}
const {

@@ -137,3 +138,2 @@ statusCode,

console.log('response received', statusCode)

@@ -140,0 +140,0 @@ console.log('headers', headers)

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

const { PassThrough } = require('stream')
const { AsyncResource } = require('async_hooks')

@@ -226,1 +227,35 @@ const transactions = new Map()

})
test('async hooks pipeline close', (t) => {
t.plan(2)
const server = createServer((req, res) => {
res.end('hello')
})
t.tearDown(server.close.bind(server))
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
t.tearDown(client.close.bind(client))
setCurrentTransaction({ hello: 'world2' })
const ret = client
.pipeline({ path: '/', method: 'GET' }, ({ body }) => {
return body
})
.on('close', () => {
t.strictDeepEqual(getCurrentTransaction(), { hello: 'world2' })
})
.on('error', (err) => {
t.ok(err)
})
.end()
new AsyncResource('tmp')
.runInAsyncScope(() => {
setCurrentTransaction({ hello: 'world1' })
ret.destroy()
})
})
})

@@ -604,1 +604,62 @@ 'use strict'

})
test('pipeline args validation', (t) => {
t.plan(2)
const client = new Client('http://localhost:5000')
const ret = client.pipeline(null, () => {})
ret.on('error', (err) => {
t.ok(/opts/.test(err.message))
t.ok(err instanceof errors.InvalidArgumentError)
})
})
test('pipeline factory throw not unhandled', (t) => {
t.plan(1)
const server = createServer((req, res) => {
res.write('asd')
})
t.tearDown(server.close.bind(server))
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
t.tearDown(client.destroy.bind(client))
client.pipeline({
path: '/',
method: 'GET'
}, (data) => {
throw new Error('asd')
})
.on('error', (err) => {
t.ok(err)
})
.end()
})
})
test('pipeline destroy before dispatch', (t) => {
t.plan(1)
const server = createServer((req, res) => {
res.end('hello')
})
t.tearDown(server.close.bind(server))
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`)
t.tearDown(client.close.bind(client))
client
.pipeline({ path: '/', method: 'GET' }, ({ body }) => {
return body
})
.on('error', (err) => {
t.ok(err)
})
.end()
.destroy()
})
})
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc