mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
deps: update undici to 5.8.2
PR-URL: https://github.com/nodejs/node/pull/44187 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
1 parent
121c54718d
commit
0484122f71
7 files changed
+64
-19
No files matched your search
+17
@@ -177,6 +177,23 @@ for await (const data of result2.body) {
|
||||
console.log('data', data.toString('utf8')) // data hello
|
||||
}
|
||||
```
|
||||
#### Example - Mock different requests within the same file
|
||||
```js
|
||||
const { MockAgent, setGlobalDispatcher } = require('undici');
|
||||
const agent = new MockAgent();
|
||||
agent.disableNetConnect();
|
||||
setGlobalDispatcher(agent);
|
||||
describe('Test', () => {
|
||||
it('200', async () => {
|
||||
const mockAgent = agent.get('http://test.com');
|
||||
// your test
|
||||
});
|
||||
it('200', async () => {
|
||||
const mockAgent = agent.get('http://testing.com');
|
||||
// your test
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
#### Example - Mocked request with query body, headers and trailers
|
||||
|
||||
|
||||
Vendored
+6
-1
@@ -53,7 +53,12 @@ function makeDispatcher (fn) {
|
||||
throw new InvalidArgumentError('invalid opts.path')
|
||||
}
|
||||
|
||||
url = new URL(opts.path, util.parseOrigin(url))
|
||||
let path = opts.path
|
||||
if (!opts.path.startsWith('/')) {
|
||||
path = `/${path}`
|
||||
}
|
||||
|
||||
url = new URL(util.parseOrigin(url).origin + path)
|
||||
} else {
|
||||
if (!opts) {
|
||||
opts = typeof url === 'object' ? url : {}
|
||||
|
||||
Vendored
+2
-1
@@ -297,7 +297,8 @@ function processHeader (request, key, val) {
|
||||
} else if (
|
||||
request.contentType === null &&
|
||||
key.length === 12 &&
|
||||
key.toLowerCase() === 'content-type'
|
||||
key.toLowerCase() === 'content-type' &&
|
||||
headerCharRegex.exec(val) === null
|
||||
) {
|
||||
request.contentType = val
|
||||
request.headers += `${key}: ${val}\r\n`
|
||||
|
||||
Vendored
+14
-3
@@ -108,14 +108,25 @@ function parseURL (url) {
|
||||
const port = url.port != null
|
||||
? url.port
|
||||
: (url.protocol === 'https:' ? 443 : 80)
|
||||
const origin = url.origin != null
|
||||
let origin = url.origin != null
|
||||
? url.origin
|
||||
: `${url.protocol}//${url.hostname}:${port}`
|
||||
const path = url.path != null
|
||||
let path = url.path != null
|
||||
? url.path
|
||||
: `${url.pathname || ''}${url.search || ''}`
|
||||
|
||||
url = new URL(path, origin)
|
||||
if (origin.endsWith('/')) {
|
||||
origin = origin.substring(0, origin.length - 1)
|
||||
}
|
||||
|
||||
if (path && !path.startsWith('/')) {
|
||||
path = `/${path}`
|
||||
}
|
||||
// new URL(path, origin) is unsafe when `path` contains an absolute URL
|
||||
// From https://developer.mozilla.org/en-US/docs/Web/API/URL/URL:
|
||||
// If first parameter is a relative URL, second param is required, and will be used as the base URL.
|
||||
// If first parameter is an absolute URL, a given second param will be ignored.
|
||||
url = new URL(origin + path)
|
||||
}
|
||||
|
||||
return url
|
||||
|
||||
Vendored
+9
-6
@@ -388,10 +388,6 @@ webidl.converters.DOMString = function (V, opts = {}) {
|
||||
return String(V)
|
||||
}
|
||||
|
||||
// Check for 0 or more characters outside of the latin1 range.
|
||||
// eslint-disable-next-line no-control-regex
|
||||
const isLatin1 = /^[\u0000-\u00ff]{0,}$/
|
||||
|
||||
// https://webidl.spec.whatwg.org/#es-ByteString
|
||||
webidl.converters.ByteString = function (V) {
|
||||
// 1. Let x be ? ToString(V).
|
||||
@@ -400,8 +396,15 @@ webidl.converters.ByteString = function (V) {
|
||||
|
||||
// 2. If the value of any element of x is greater than
|
||||
// 255, then throw a TypeError.
|
||||
if (!isLatin1.test(x)) {
|
||||
throw new TypeError('Argument is not a ByteString')
|
||||
for (let index = 0; index < x.length; index++) {
|
||||
const charCode = x.charCodeAt(index)
|
||||
|
||||
if (charCode > 255) {
|
||||
throw new TypeError(
|
||||
'Cannot convert argument to a ByteString because the character at' +
|
||||
`index ${index} has a value of ${charCode} which is greater than 255.`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Return an IDL ByteString value whose length is the
|
||||
|
||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "undici",
|
||||
"version": "5.8.1",
|
||||
"version": "5.8.2",
|
||||
"description": "An HTTP/1.1 client, written from scratch for Node.js",
|
||||
"homepage": "https://undici.nodejs.org",
|
||||
"bugs": {
|
||||
|
||||
Vendored
+15
-7
@@ -737,9 +737,15 @@ var require_util = __commonJS({
|
||||
}
|
||||
if (!(url instanceof URL)) {
|
||||
const port = url.port != null ? url.port : url.protocol === "https:" ? 443 : 80;
|
||||
const origin = url.origin != null ? url.origin : `${url.protocol}//${url.hostname}:${port}`;
|
||||
const path = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`;
|
||||
url = new URL(path, origin);
|
||||
let origin = url.origin != null ? url.origin : `${url.protocol}//${url.hostname}:${port}`;
|
||||
let path = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`;
|
||||
if (origin.endsWith("/")) {
|
||||
origin = origin.substring(0, origin.length - 1);
|
||||
}
|
||||
if (path && !path.startsWith("/")) {
|
||||
path = `/${path}`;
|
||||
}
|
||||
url = new URL(origin + path);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
@@ -1281,11 +1287,13 @@ var require_webidl = __commonJS({
|
||||
}
|
||||
return String(V);
|
||||
};
|
||||
var isLatin1 = /^[\u0000-\u00ff]{0,}$/;
|
||||
webidl.converters.ByteString = function(V) {
|
||||
const x = webidl.converters.DOMString(V);
|
||||
if (!isLatin1.test(x)) {
|
||||
throw new TypeError("Argument is not a ByteString");
|
||||
for (let index = 0; index < x.length; index++) {
|
||||
const charCode = x.charCodeAt(index);
|
||||
if (charCode > 255) {
|
||||
throw new TypeError(`Cannot convert argument to a ByteString because the character atindex ${index} has a value of ${charCode} which is greater than 255.`);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
};
|
||||
@@ -2580,7 +2588,7 @@ var require_request = __commonJS({
|
||||
if (!Number.isFinite(request.contentLength)) {
|
||||
throw new InvalidArgumentError("invalid content-length header");
|
||||
}
|
||||
} else if (request.contentType === null && key.length === 12 && key.toLowerCase() === "content-type") {
|
||||
} else if (request.contentType === null && key.length === 12 && key.toLowerCase() === "content-type" && headerCharRegex.exec(val) === null) {
|
||||
request.contentType = val;
|
||||
request.headers += `${key}: ${val}\r
|
||||
`;
|
||||
|
||||
Reference in new issue
Block a user