Comparing version 6.18.2 to 6.19.0
@@ -22,3 +22,3 @@ # Class: Client | ||
* **bodyTimeout** `number | null` (optional) - Default: `300e3` - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 300 seconds. | ||
* **bodyTimeout** `number | null` (optional) - Default: `300e3` - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 300 seconds. Please note the `timeout` will be reset if you keep writing data to the scoket everytime. | ||
* **headersTimeout** `number | null` (optional) - Default: `300e3` - The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds. | ||
@@ -25,0 +25,0 @@ * **keepAliveMaxTimeout** `number | null` (optional) - Default: `600e3` - The maximum allowed `keepAliveTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Defaults to 10 minutes. |
@@ -76,3 +76,3 @@ 'use strict' | ||
function buildConnector ({ allowH2, maxCachedSessions, socketPath, timeout, ...opts }) { | ||
function buildConnector ({ allowH2, maxCachedSessions, socketPath, timeout, session: customSession, ...opts }) { | ||
if (maxCachedSessions != null && (!Number.isInteger(maxCachedSessions) || maxCachedSessions < 0)) { | ||
@@ -95,3 +95,3 @@ throw new InvalidArgumentError('maxCachedSessions must be a positive integer or zero') | ||
const sessionKey = servername || hostname | ||
const session = sessionCache.get(sessionKey) || null | ||
const session = customSession || sessionCache.get(sessionKey) || null | ||
@@ -98,0 +98,0 @@ assert(sessionKey) |
@@ -19,3 +19,4 @@ 'use strict' | ||
validateHandler, | ||
getServerName | ||
getServerName, | ||
normalizedMethodRecords | ||
} = require('./util') | ||
@@ -55,3 +56,3 @@ const { channels } = require('./diagnostics.js') | ||
throw new InvalidArgumentError('path must be an absolute URL or start with a slash') | ||
} else if (invalidPathRegex.exec(path) !== null) { | ||
} else if (invalidPathRegex.test(path)) { | ||
throw new InvalidArgumentError('invalid request path') | ||
@@ -62,3 +63,3 @@ } | ||
throw new InvalidArgumentError('method must be a string') | ||
} else if (!isValidHTTPToken(method)) { | ||
} else if (normalizedMethodRecords[method] === undefined && !isValidHTTPToken(method)) { | ||
throw new InvalidArgumentError('invalid request method') | ||
@@ -65,0 +66,0 @@ } |
@@ -648,2 +648,27 @@ 'use strict' | ||
const normalizedMethodRecordsBase = { | ||
delete: 'DELETE', | ||
DELETE: 'DELETE', | ||
get: 'GET', | ||
GET: 'GET', | ||
head: 'HEAD', | ||
HEAD: 'HEAD', | ||
options: 'OPTIONS', | ||
OPTIONS: 'OPTIONS', | ||
post: 'POST', | ||
POST: 'POST', | ||
put: 'PUT', | ||
PUT: 'PUT' | ||
} | ||
const normalizedMethodRecords = { | ||
...normalizedMethodRecordsBase, | ||
patch: 'patch', | ||
PATCH: 'PATCH' | ||
} | ||
// Note: object prototypes should not be able to be referenced. e.g. `Object#hasOwnProperty`. | ||
Object.setPrototypeOf(normalizedMethodRecordsBase, null) | ||
Object.setPrototypeOf(normalizedMethodRecords, null) | ||
module.exports = { | ||
@@ -687,2 +712,4 @@ kEnumerableProperty, | ||
parseRangeHeader, | ||
normalizedMethodRecordsBase, | ||
normalizedMethodRecords, | ||
isValidPort, | ||
@@ -689,0 +716,0 @@ isHttpOrHttpsPrefixed, |
@@ -981,15 +981,15 @@ 'use strict' | ||
if (!body || bodyLength === 0) { | ||
writeBuffer({ abort, body: null, client, request, socket, contentLength, header, expectsPayload }) | ||
writeBuffer(abort, null, client, request, socket, contentLength, header, expectsPayload) | ||
} else if (util.isBuffer(body)) { | ||
writeBuffer({ abort, body, client, request, socket, contentLength, header, expectsPayload }) | ||
writeBuffer(abort, body, client, request, socket, contentLength, header, expectsPayload) | ||
} else if (util.isBlobLike(body)) { | ||
if (typeof body.stream === 'function') { | ||
writeIterable({ abort, body: body.stream(), client, request, socket, contentLength, header, expectsPayload }) | ||
writeIterable(abort, body.stream(), client, request, socket, contentLength, header, expectsPayload) | ||
} else { | ||
writeBlob({ abort, body, client, request, socket, contentLength, header, expectsPayload }) | ||
writeBlob(abort, body, client, request, socket, contentLength, header, expectsPayload) | ||
} | ||
} else if (util.isStream(body)) { | ||
writeStream({ abort, body, client, request, socket, contentLength, header, expectsPayload }) | ||
writeStream(abort, body, client, request, socket, contentLength, header, expectsPayload) | ||
} else if (util.isIterable(body)) { | ||
writeIterable({ abort, body, client, request, socket, contentLength, header, expectsPayload }) | ||
writeIterable(abort, body, client, request, socket, contentLength, header, expectsPayload) | ||
} else { | ||
@@ -1002,3 +1002,3 @@ assert(false) | ||
function writeStream ({ abort, body, client, request, socket, contentLength, header, expectsPayload }) { | ||
function writeStream (abort, body, client, request, socket, contentLength, header, expectsPayload) { | ||
assert(contentLength !== 0 || client[kRunning] === 0, 'stream body cannot be pipelined') | ||
@@ -1106,3 +1106,3 @@ | ||
function writeBuffer ({ abort, body, client, request, socket, contentLength, header, expectsPayload }) { | ||
function writeBuffer (abort, body, client, request, socket, contentLength, header, expectsPayload) { | ||
try { | ||
@@ -1137,3 +1137,3 @@ if (!body) { | ||
async function writeBlob ({ abort, body, client, request, socket, contentLength, header, expectsPayload }) { | ||
async function writeBlob (abort, body, client, request, socket, contentLength, header, expectsPayload) { | ||
assert(contentLength === body.size, 'blob body must have content length') | ||
@@ -1166,3 +1166,3 @@ | ||
async function writeIterable ({ abort, body, client, request, socket, contentLength, header, expectsPayload }) { | ||
async function writeIterable (abort, body, client, request, socket, contentLength, header, expectsPayload) { | ||
assert(contentLength !== 0 || client[kRunning] === 0, 'iterator body cannot be pipelined') | ||
@@ -1169,0 +1169,0 @@ |
@@ -480,71 +480,69 @@ 'use strict' | ||
if (!body || contentLength === 0) { | ||
writeBuffer({ | ||
writeBuffer( | ||
abort, | ||
stream, | ||
null, | ||
client, | ||
request, | ||
client[kSocket], | ||
contentLength, | ||
expectsPayload, | ||
h2stream: stream, | ||
body: null, | ||
socket: client[kSocket] | ||
}) | ||
expectsPayload | ||
) | ||
} else if (util.isBuffer(body)) { | ||
writeBuffer({ | ||
writeBuffer( | ||
abort, | ||
stream, | ||
body, | ||
client, | ||
request, | ||
client[kSocket], | ||
contentLength, | ||
body, | ||
expectsPayload, | ||
h2stream: stream, | ||
socket: client[kSocket] | ||
}) | ||
expectsPayload | ||
) | ||
} else if (util.isBlobLike(body)) { | ||
if (typeof body.stream === 'function') { | ||
writeIterable({ | ||
writeIterable( | ||
abort, | ||
stream, | ||
body.stream(), | ||
client, | ||
request, | ||
client[kSocket], | ||
contentLength, | ||
expectsPayload, | ||
h2stream: stream, | ||
body: body.stream(), | ||
socket: client[kSocket] | ||
}) | ||
expectsPayload | ||
) | ||
} else { | ||
writeBlob({ | ||
writeBlob( | ||
abort, | ||
stream, | ||
body, | ||
client, | ||
request, | ||
client[kSocket], | ||
contentLength, | ||
expectsPayload, | ||
h2stream: stream, | ||
socket: client[kSocket] | ||
}) | ||
expectsPayload | ||
) | ||
} | ||
} else if (util.isStream(body)) { | ||
writeStream({ | ||
writeStream( | ||
abort, | ||
client[kSocket], | ||
expectsPayload, | ||
stream, | ||
body, | ||
client, | ||
request, | ||
contentLength, | ||
expectsPayload, | ||
socket: client[kSocket], | ||
h2stream: stream, | ||
header: '' | ||
}) | ||
contentLength | ||
) | ||
} else if (util.isIterable(body)) { | ||
writeIterable({ | ||
writeIterable( | ||
abort, | ||
stream, | ||
body, | ||
client, | ||
request, | ||
client[kSocket], | ||
contentLength, | ||
expectsPayload, | ||
header: '', | ||
h2stream: stream, | ||
socket: client[kSocket] | ||
}) | ||
expectsPayload | ||
) | ||
} else { | ||
@@ -556,3 +554,3 @@ assert(false) | ||
function writeBuffer ({ abort, h2stream, body, client, request, socket, contentLength, expectsPayload }) { | ||
function writeBuffer (abort, h2stream, body, client, request, socket, contentLength, expectsPayload) { | ||
try { | ||
@@ -580,3 +578,3 @@ if (body != null && util.isBuffer(body)) { | ||
function writeStream ({ abort, socket, expectsPayload, h2stream, body, client, request, contentLength }) { | ||
function writeStream (abort, socket, expectsPayload, h2stream, body, client, request, contentLength) { | ||
assert(contentLength !== 0 || client[kRunning] === 0, 'stream body cannot be pipelined') | ||
@@ -612,3 +610,3 @@ | ||
async function writeBlob ({ abort, h2stream, body, client, request, socket, contentLength, expectsPayload }) { | ||
async function writeBlob (abort, h2stream, body, client, request, socket, contentLength, expectsPayload) { | ||
assert(contentLength === body.size, 'blob body must have content length') | ||
@@ -641,3 +639,3 @@ | ||
async function writeIterable ({ abort, h2stream, body, client, request, socket, contentLength, expectsPayload }) { | ||
async function writeIterable (abort, h2stream, body, client, request, socket, contentLength, expectsPayload) { | ||
assert(contentLength !== 0 || client[kRunning] === 0, 'iterator body cannot be pipelined') | ||
@@ -644,0 +642,0 @@ |
@@ -205,3 +205,3 @@ 'use strict' | ||
headers, | ||
count: this.retryCount | ||
data: { count: this.retryCount } | ||
}) | ||
@@ -217,3 +217,3 @@ ) | ||
headers, | ||
count: this.retryCount | ||
data: { count: this.retryCount } | ||
}) | ||
@@ -220,0 +220,0 @@ ) |
@@ -13,5 +13,3 @@ /* globals AbortController */ | ||
sameOrigin, | ||
normalizeMethod, | ||
environmentSettingsObject, | ||
normalizeMethodRecord | ||
environmentSettingsObject | ||
} = require('./util') | ||
@@ -28,3 +26,3 @@ const { | ||
} = require('./constants') | ||
const { kEnumerableProperty } = util | ||
const { kEnumerableProperty, normalizedMethodRecordsBase, normalizedMethodRecords } = util | ||
const { kHeaders, kSignal, kState, kDispatcher } = require('./symbols') | ||
@@ -354,3 +352,3 @@ const { webidl } = require('./webidl') | ||
const mayBeNormalized = normalizeMethodRecord[method] | ||
const mayBeNormalized = normalizedMethodRecords[method] | ||
@@ -367,3 +365,5 @@ if (mayBeNormalized !== undefined) { | ||
if (forbiddenMethodsSet.has(method.toUpperCase())) { | ||
const upperCase = method.toUpperCase() | ||
if (forbiddenMethodsSet.has(upperCase)) { | ||
throw new TypeError(`'${method}' HTTP method is unsupported.`) | ||
@@ -373,3 +373,5 @@ } | ||
// 3. Normalize method. | ||
method = normalizeMethod(method) | ||
// https://fetch.spec.whatwg.org/#concept-method-normalize | ||
// Note: must be in uppercase | ||
method = normalizedMethodRecordsBase[upperCase] ?? method | ||
@@ -376,0 +378,0 @@ // 4. Set request’s method to method. |
@@ -9,3 +9,3 @@ 'use strict' | ||
const { performance } = require('node:perf_hooks') | ||
const { isBlobLike, ReadableStreamFrom, isValidHTTPToken } = require('../../core/util') | ||
const { isBlobLike, ReadableStreamFrom, isValidHTTPToken, normalizedMethodRecordsBase } = require('../../core/util') | ||
const assert = require('node:assert') | ||
@@ -795,27 +795,2 @@ const { isUint8Array } = require('node:util/types') | ||
const normalizeMethodRecordBase = { | ||
delete: 'DELETE', | ||
DELETE: 'DELETE', | ||
get: 'GET', | ||
GET: 'GET', | ||
head: 'HEAD', | ||
HEAD: 'HEAD', | ||
options: 'OPTIONS', | ||
OPTIONS: 'OPTIONS', | ||
post: 'POST', | ||
POST: 'POST', | ||
put: 'PUT', | ||
PUT: 'PUT' | ||
} | ||
const normalizeMethodRecord = { | ||
...normalizeMethodRecordBase, | ||
patch: 'patch', | ||
PATCH: 'PATCH' | ||
} | ||
// Note: object prototypes should not be able to be referenced. e.g. `Object#hasOwnProperty`. | ||
Object.setPrototypeOf(normalizeMethodRecordBase, null) | ||
Object.setPrototypeOf(normalizeMethodRecord, null) | ||
/** | ||
@@ -826,3 +801,3 @@ * @see https://fetch.spec.whatwg.org/#concept-method-normalize | ||
function normalizeMethod (method) { | ||
return normalizeMethodRecordBase[method.toLowerCase()] ?? method | ||
return normalizedMethodRecordsBase[method.toLowerCase()] ?? method | ||
} | ||
@@ -1645,3 +1620,2 @@ | ||
readAllBytes, | ||
normalizeMethodRecord, | ||
simpleRangeHeaderValue, | ||
@@ -1648,0 +1622,0 @@ buildContentRange, |
@@ -31,4 +31,2 @@ 'use strict' | ||
let experimentalWarned = false | ||
// https://websockets.spec.whatwg.org/#interface-definition | ||
@@ -60,9 +58,2 @@ class WebSocket extends EventTarget { | ||
if (!experimentalWarned) { | ||
experimentalWarned = true | ||
process.emitWarning('WebSockets are experimental, expect them to change at any time.', { | ||
code: 'UNDICI-WS' | ||
}) | ||
} | ||
const options = webidl.converters['DOMString or sequence<DOMString> or WebSocketInit'](protocols, prefix, 'options') | ||
@@ -69,0 +60,0 @@ |
{ | ||
"name": "undici", | ||
"version": "6.18.2", | ||
"version": "6.19.0", | ||
"description": "An HTTP/1.1 client, written from scratch for Node.js", | ||
@@ -110,4 +110,4 @@ "homepage": "https://undici.nodejs.org", | ||
"abort-controller": "^3.0.0", | ||
"borp": "^0.14.0", | ||
"c8": "^9.1.0", | ||
"borp": "^0.15.0", | ||
"c8": "^10.0.0", | ||
"cross-env": "^7.0.3", | ||
@@ -114,0 +114,0 @@ "dns-packet": "^5.4.0", |
@@ -128,2 +128,23 @@ import { IncomingHttpHeaders } from "./header"; | ||
} | ||
export class RequestRetryError extends UndiciError { | ||
constructor ( | ||
message: string, | ||
statusCode: number, | ||
headers?: IncomingHttpHeaders | string[] | null, | ||
body?: null | Record<string, any> | string | ||
); | ||
name: 'RequestRetryError'; | ||
code: 'UND_ERR_REQ_RETRY'; | ||
statusCode: number; | ||
data: { | ||
count: number; | ||
}; | ||
headers: Record<string, string | string[]>; | ||
} | ||
export class SecureProxyConnectionError extends UndiciError { | ||
name: 'SecureProxyConnectionError'; | ||
code: 'UND_ERR_PRX_TLS'; | ||
} | ||
} |
@@ -21,2 +21,3 @@ import Dispatcher from'./dispatcher' | ||
import { request, pipeline, stream, connect, upgrade } from './api' | ||
import interceptors from './interceptors' | ||
@@ -36,3 +37,3 @@ export * from './util' | ||
export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent, request, stream, pipeline, connect, upgrade, setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, getGlobalOrigin, MockClient, MockPool, MockAgent, mockErrors, ProxyAgent, EnvHttpProxyAgent, RedirectHandler, DecoratorHandler, RetryHandler, RetryAgent } | ||
export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent, request, stream, pipeline, connect, upgrade, setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, getGlobalOrigin, interceptors, MockClient, MockPool, MockAgent, mockErrors, ProxyAgent, EnvHttpProxyAgent, RedirectHandler, DecoratorHandler, RetryHandler, RetryAgent } | ||
export default Undici | ||
@@ -39,0 +40,0 @@ |
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
1132832
23969