Socket
Socket
Sign inDemoInstall

undici

Package Overview
Dependencies
Maintainers
2
Versions
211
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 2.0.4 to 2.0.5

test/socket-back-pressure.js

65

lib/core/client.js

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

SocketTimeoutError,
TrailerMismatchError,
InvalidArgumentError,

@@ -498,7 +499,22 @@ RequestAbortedError,

let keepAlive
let trailers
for (let n = 0; n < this.headers.length; n += 2) {
const key = this.headers[n + 0]
const val = this.headers[n + 1]
if (!keepAlive && key.length === 10 && key.toLowerCase() === 'keep-alive') {
keepAlive = val
} else if (!trailers && key.length === 7 && key.toLowerCase() === 'trailer') {
trailers = val
}
}
const { headers } = this
this.headers = null
this.trailers = trailers ? trailers.toLowerCase().split(/,\s*/) : null
if (shouldKeepAlive && client[kKeepAlive]) {
const keepAliveTimeout = util.parseKeepAliveTimeout(headers)
const keepAliveTimeout = keepAlive ? util.parseKeepAliveTimeout(keepAlive) : null

@@ -544,3 +560,3 @@ if (keepAliveTimeout != null) {

if (request.onBody(chunk, offset, length) === false) {
socket.pause()
socket[kPause]()
}

@@ -553,3 +569,3 @@ } catch (err) {

[HTTPParser.kOnMessageComplete] () {
const { client, socket, statusCode, headers, upgrade, request } = this
const { client, socket, statusCode, headers, upgrade, request, trailers } = this

@@ -571,2 +587,3 @@ if (socket.destroyed) {

this.request = null
this.trailers = null

@@ -579,2 +596,22 @@ if (statusCode < 200) {

try {
if (trailers) {
if (!headers) {
throw new TrailerMismatchError()
}
for (const trailer of trailers) {
let found = false
for (let n = 0; n < headers.length; n += 2) {
const key = headers[n + 0]
if (key.length === trailer.length && key.toLowerCase() === trailer.toLowerCase()) {
found = true
break
}
}
if (!found) {
throw new TrailerMismatchError()
}
}
}
request.onComplete(headers)

@@ -602,3 +639,3 @@ } catch (err) {

} else {
socket.resume()
socket[kResume]()
resume(client)

@@ -752,4 +789,4 @@ }

socket[kPause] = socket.pause.bind(socket)
socket[kResume] = socket.resume.bind(socket)
socket[kPause] = socketPause.bind(socket)
socket[kResume] = socketResume.bind(socket)
socket[kError] = null

@@ -768,2 +805,18 @@ socket[kParser] = parser

function socketPause () {
// TODO: Pause parser.
if (this._handle && this._handle.reading) {
this._handle.reading = false
this._handle.readStop()
}
}
function socketResume () {
// TODO: Resume parser.
if (this._handle && !this._handle.reading) {
this._handle.reading = true
this._handle.readStart()
}
}
function emitDrain (client) {

@@ -770,0 +823,0 @@ client[kNeedDrain] = 0

@@ -91,2 +91,12 @@ 'use strict'

class TrailerMismatchError extends UndiciError {
constructor (message) {
super(message)
Error.captureStackTrace(this, TrailerMismatchError)
this.name = 'TrailerMismatchError'
this.message = message || /* istanbul ignore next */ 'Trailers does not match trailer header'
this.code = 'UND_ERR_TRAILER_MISMATCH'
}
}
class ClientDestroyedError extends UndiciError {

@@ -138,2 +148,3 @@ constructor (message) {

ContentLengthMismatchError,
TrailerMismatchError,
InvalidArgumentError,

@@ -140,0 +151,0 @@ InvalidReturnValueError,

11

lib/core/util.js

@@ -51,10 +51,5 @@ 'use strict'

const KEEPALIVE_TIMEOUT_EXPR = /timeout=(\d+)s/
function parseKeepAliveTimeout (headers) {
for (let n = 0; n < headers.length; n += 2) {
const key = headers[n + 0]
if (key.length === 10 && key.toLowerCase() === 'keep-alive') {
const m = headers[n + 1].match(KEEPALIVE_TIMEOUT_EXPR)
return m ? parseInt(m[1]) * 1000 : null
}
}
function parseKeepAliveTimeout (val) {
const m = val.match(KEEPALIVE_TIMEOUT_EXPR)
return m ? parseInt(m[1]) * 1000 : null
}

@@ -61,0 +56,0 @@

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

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

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

| `InformationalError` | `UND_ERR_INFO` | expected error with reason |
| `TrailerMismatchError` | `UND_ERR_TRAILER_MISMATCH` | trailers did not match specification |

@@ -629,0 +630,0 @@ ## Specification Compliance

@@ -938,5 +938,6 @@ 'use strict'

t.ok(err)
t.is('ECONNREFUSED', err.code)
// TODO: Why UND_ERR_SOCKET?
t.ok(err.code === 'ECONNREFUSED' || err.code === 'UND_ERR_SOCKET', err.code)
t.end()
})
})

@@ -568,4 +568,4 @@ 'use strict'

}, () => new PassThrough(), (err, data) => {
t.strictDeepEqual({ 'content-md5': 'test' }, data.trailers)
t.error(err)
t.strictDeepEqual(data.trailers, { 'content-md5': 'test' })
})

@@ -572,0 +572,0 @@ })

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc