Comparing version 5.18.0 to 5.19.0
@@ -66,3 +66,4 @@ # Class: MockPool | ||
* **reply** `(statusCode: number, replyData: string | Buffer | object | MockInterceptor.MockResponseDataHandler, responseOptions?: MockResponseOptions) => MockScope` - define a reply for a matching request. You can define this as a callback to read incoming request data. Default for `responseOptions` is `{}`. | ||
* **reply** `(statusCode: number, replyData: string | Buffer | object | MockInterceptor.MockResponseDataHandler, responseOptions?: MockResponseOptions) => MockScope` - define a reply for a matching request. You can define the replyData as a callback to read incoming request data. Default for `responseOptions` is `{}`. | ||
* **reply** `(callback: MockInterceptor.MockReplyOptionsCallback) => MockScope` - define a reply for a matching request, allowing dynamic mocking of all reply options rather than just the data. | ||
* **replyWithError** `(error: Error) => MockScope` - define an error for a matching request to throw. | ||
@@ -69,0 +70,0 @@ * **defaultReplyHeaders** `(headers: Record<string, string>) => MockInterceptor` - define default headers to be included in subsequent replies. These are in addition to headers on a specific reply. |
@@ -86,3 +86,4 @@ 'use strict' | ||
return cookies.map((pair) => parseSetCookie(pair[1])) | ||
// In older versions of undici, cookies is a list of name:value. | ||
return cookies.map((pair) => parseSetCookie(Array.isArray(pair) ? pair[1] : pair)) | ||
} | ||
@@ -89,0 +90,0 @@ |
@@ -216,2 +216,7 @@ 'use strict' | ||
let val = obj[key] | ||
const encoding = key.length === 19 && key === 'content-disposition' | ||
? 'latin1' | ||
: 'utf8' | ||
if (!val) { | ||
@@ -221,3 +226,3 @@ if (Array.isArray(headers[i + 1])) { | ||
} else { | ||
obj[key] = headers[i + 1].toString() | ||
obj[key] = headers[i + 1].toString(encoding) | ||
} | ||
@@ -229,3 +234,3 @@ } else { | ||
} | ||
val.push(headers[i + 1].toString()) | ||
val.push(headers[i + 1].toString(encoding)) | ||
} | ||
@@ -237,3 +242,15 @@ } | ||
function parseRawHeaders (headers) { | ||
return headers.map(header => header.toString()) | ||
const ret = [] | ||
for (let n = 0; n < headers.length; n += 2) { | ||
const key = headers[n + 0].toString() | ||
const encoding = key.length === 19 && key.toLowerCase() === 'content-disposition' | ||
? 'latin1' | ||
: 'utf8' | ||
const val = headers[n + 1].toString(encoding) | ||
ret.push(key, val) | ||
} | ||
return ret | ||
} | ||
@@ -240,0 +257,0 @@ |
@@ -14,2 +14,3 @@ // https://github.com/Ethan-Arrowood/undici-fetch | ||
const { webidl } = require('./webidl') | ||
const assert = require('assert') | ||
@@ -119,3 +120,3 @@ const kHeadersMap = Symbol('headers map') | ||
this.cookies ??= [] | ||
this.cookies.push([name, value]) | ||
this.cookies.push(value) | ||
} | ||
@@ -130,3 +131,3 @@ } | ||
if (lowercaseName === 'set-cookie') { | ||
this.cookies = [[name, value]] | ||
this.cookies = [value] | ||
} | ||
@@ -389,7 +390,63 @@ | ||
// https://fetch.spec.whatwg.org/#dom-headers-getsetcookie | ||
getSetCookie () { | ||
webidl.brandCheck(this, Headers) | ||
// 1. If this’s header list does not contain `Set-Cookie`, then return « ». | ||
// 2. Return the values of all headers in this’s header list whose name is | ||
// a byte-case-insensitive match for `Set-Cookie`, in order. | ||
const list = this[kHeadersList].cookies | ||
if (list) { | ||
return [...list] | ||
} | ||
return [] | ||
} | ||
// https://fetch.spec.whatwg.org/#concept-header-list-sort-and-combine | ||
get [kHeadersSortedMap] () { | ||
if (!this[kHeadersList][kHeadersSortedMap]) { | ||
this[kHeadersList][kHeadersSortedMap] = new Map([...this[kHeadersList]].sort((a, b) => a[0] < b[0] ? -1 : 1)) | ||
if (this[kHeadersList][kHeadersSortedMap]) { | ||
return this[kHeadersList][kHeadersSortedMap] | ||
} | ||
return this[kHeadersList][kHeadersSortedMap] | ||
// 1. Let headers be an empty list of headers with the key being the name | ||
// and value the value. | ||
const headers = [] | ||
// 2. Let names be the result of convert header names to a sorted-lowercase | ||
// set with all the names of the headers in list. | ||
const names = [...this[kHeadersList]].sort((a, b) => a[0] < b[0] ? -1 : 1) | ||
const cookies = this[kHeadersList].cookies | ||
// 3. For each name of names: | ||
for (const [name, value] of names) { | ||
// 1. If name is `set-cookie`, then: | ||
if (name === 'set-cookie') { | ||
// 1. Let values be a list of all values of headers in list whose name | ||
// is a byte-case-insensitive match for name, in order. | ||
// 2. For each value of values: | ||
// 1. Append (name, value) to headers. | ||
for (const value of cookies) { | ||
headers.push([name, value]) | ||
} | ||
} else { | ||
// 2. Otherwise: | ||
// 1. Let value be the result of getting name from list. | ||
// 2. Assert: value is non-null. | ||
assert(value !== null) | ||
// 3. Append (name, value) to headers. | ||
headers.push([name, value]) | ||
} | ||
} | ||
this[kHeadersList][kHeadersSortedMap] = headers | ||
// 4. Return headers. | ||
return headers | ||
} | ||
@@ -401,3 +458,3 @@ | ||
return makeIterator( | ||
() => [...this[kHeadersSortedMap].entries()], | ||
() => [...this[kHeadersSortedMap].values()], | ||
'Headers', | ||
@@ -412,3 +469,3 @@ 'key' | ||
return makeIterator( | ||
() => [...this[kHeadersSortedMap].entries()], | ||
() => [...this[kHeadersSortedMap].values()], | ||
'Headers', | ||
@@ -423,3 +480,3 @@ 'value' | ||
return makeIterator( | ||
() => [...this[kHeadersSortedMap].entries()], | ||
() => [...this[kHeadersSortedMap].values()], | ||
'Headers', | ||
@@ -426,0 +483,0 @@ 'key+value' |
@@ -31,2 +31,3 @@ /* globals AbortController */ | ||
const assert = require('assert') | ||
const { setMaxListeners, getEventListeners, defaultMaxListeners } = require('events') | ||
@@ -356,2 +357,7 @@ let TransformStream = globalThis.TransformStream | ||
} | ||
if (getEventListeners(signal, 'abort').length >= defaultMaxListeners) { | ||
setMaxListeners(100, signal) | ||
} | ||
signal.addEventListener('abort', abort, { once: true }) | ||
@@ -358,0 +364,0 @@ requestFinalizer.register(this, { signal, abort }) |
@@ -191,3 +191,7 @@ 'use strict' | ||
function generateKeyValues (data) { | ||
return Object.entries(data).reduce((keyValuePairs, [key, value]) => [...keyValuePairs, key, value], []) | ||
return Object.entries(data).reduce((keyValuePairs, [key, value]) => [ | ||
...keyValuePairs, | ||
Buffer.from(`${key}`), | ||
Array.isArray(value) ? value.map(x => Buffer.from(`${x}`)) : Buffer.from(`${value}`) | ||
], []) | ||
} | ||
@@ -194,0 +198,0 @@ |
{ | ||
"name": "undici", | ||
"version": "5.18.0", | ||
"version": "5.19.0", | ||
"description": "An HTTP/1.1 client, written from scratch for Node.js", | ||
@@ -5,0 +5,0 @@ "homepage": "https://undici.nodejs.org", |
@@ -13,2 +13,4 @@ import { TLSSocket, ConnectionOptions } from 'tls' | ||
port?: number; | ||
keepAlive?: boolean | null; | ||
keepAliveInitialDelay?: number | null; | ||
} | ||
@@ -15,0 +17,0 @@ |
@@ -62,2 +62,3 @@ // based on https://github.com/Ethan-Arrowood/undici-fetch/blob/249269714db874351589d2d364a0645d5160ae71/index.d.ts (MIT license) | ||
readonly set: (name: string, value: string) => void | ||
readonly getSetCookie: () => string[] | ||
readonly forEach: ( | ||
@@ -64,0 +65,0 @@ callbackfn: (value: string, key: string, iterable: Headers) => void, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1078357
18125
0
55