GeezerVison is showing github.com — deps: update undici to 5.8.2 · nodejs/node@273014b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: deps/undici/src/docs/api/MockAgent.md +17Lines changed: 17 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -177,6 +177,23 @@ for await (const data of result2.body) { | 177 | 177 | console.log('data', data.toString('utf8')) // data hello | 178 | 178 | } | 179 | 179 | ``` | | 180 | +#### Example - Mock different requests within the same file | | 181 | +```js | | 182 | +const { MockAgent, setGlobalDispatcher } = require('undici'); | | 183 | +const agent = new MockAgent(); | | 184 | +agent.disableNetConnect(); | | 185 | +setGlobalDispatcher(agent); | | 186 | +describe('Test', () => { | | 187 | + it('200', async () => { | | 188 | + const mockAgent = agent.get('http://test.com'); | | 189 | + // your test | | 190 | + }); | | 191 | + it('200', async () => { | | 192 | + const mockAgent = agent.get('http://testing.com'); | | 193 | + // your test | | 194 | + }); | | 195 | +}); | | 196 | +``` | 180 | 197 |
| 181 | 198 | #### Example - Mocked request with query body, headers and trailers | 182 | 199 |
| |
Collapse file Copy file name to clipboardExpand all lines: deps/undici/src/index.js +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,7 +53,12 @@ function makeDispatcher (fn) { | 53 | 53 | throw new InvalidArgumentError('invalid opts.path') | 54 | 54 | } | 55 | 55 |
| 56 | | - url = new URL(opts.path, util.parseOrigin(url)) | | 56 | + let path = opts.path | | 57 | + if (!opts.path.startsWith('/')) { | | 58 | + path = `/${path}` | | 59 | + } | | 60 | + | | 61 | + url = new URL(util.parseOrigin(url).origin + path) | 57 | 62 | } else { | 58 | 63 | if (!opts) { | 59 | 64 | opts = typeof url === 'object' ? url : {} | |
Collapse file Copy file name to clipboardExpand all lines: deps/undici/src/lib/core/request.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -297,7 +297,8 @@ function processHeader (request, key, val) { | 297 | 297 | } else if ( | 298 | 298 | request.contentType === null && | 299 | 299 | key.length === 12 && | 300 | | - key.toLowerCase() === 'content-type' | | 300 | + key.toLowerCase() === 'content-type' && | | 301 | + headerCharRegex.exec(val) === null | 301 | 302 | ) { | 302 | 303 | request.contentType = val | 303 | 304 | request.headers += `${key}: ${val}\r\n` | |
Collapse file Copy file name to clipboardExpand all lines: deps/undici/src/lib/core/util.js +14-3Lines changed: 14 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -108,14 +108,25 @@ function parseURL (url) { | 108 | 108 | const port = url.port != null | 109 | 109 | ? url.port | 110 | 110 | : (url.protocol === 'https:' ? 443 : 80) | 111 | | - const origin = url.origin != null | | 111 | + let origin = url.origin != null | 112 | 112 | ? url.origin | 113 | 113 | : `${url.protocol}//${url.hostname}:${port}` | 114 | | - const path = url.path != null | | 114 | + let path = url.path != null | 115 | 115 | ? url.path | 116 | 116 | : `${url.pathname || ''}${url.search || ''}` | 117 | 117 |
| 118 | | - url = new URL(path, origin) | | 118 | + if (origin.endsWith('/')) { | | 119 | + origin = origin.substring(0, origin.length - 1) | | 120 | + } | | 121 | + | | 122 | + if (path && !path.startsWith('/')) { | | 123 | + path = `/${path}` | | 124 | + } | | 125 | + // new URL(path, origin) is unsafe when `path` contains an absolute URL | | 126 | + // From https://developer.mozilla.org/en-US/docs/Web/API/URL/URL: | | 127 | + // If first parameter is a relative URL, second param is required, and will be used as the base URL. | | 128 | + // If first parameter is an absolute URL, a given second param will be ignored. | | 129 | + url = new URL(origin + path) | 119 | 130 | } | 120 | 131 |
| 121 | 132 | return url | |
Collapse file Copy file name to clipboardExpand all lines: deps/undici/src/lib/fetch/webidl.js +9-6Lines changed: 9 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -388,10 +388,6 @@ webidl.converters.DOMString = function (V, opts = {}) { | 388 | 388 | return String(V) | 389 | 389 | } | 390 | 390 |
| 391 | | -// Check for 0 or more characters outside of the latin1 range. | 392 | | -// eslint-disable-next-line no-control-regex | 393 | | -const isLatin1 = /^[\u0000-\u00ff]{0,}$/ | 394 | | - | 395 | 391 | // https://webidl.spec.whatwg.org/#es-ByteString | 396 | 392 | webidl.converters.ByteString = function (V) { | 397 | 393 | // 1. Let x be ? ToString(V). | @@ -400,8 +396,15 @@ webidl.converters.ByteString = function (V) { | 400 | 396 |
| 401 | 397 | // 2. If the value of any element of x is greater than | 402 | 398 | // 255, then throw a TypeError. | 403 | | - if (!isLatin1.test(x)) { | 404 | | - throw new TypeError('Argument is not a ByteString') | | 399 | + for (let index = 0; index < x.length; index++) { | | 400 | + const charCode = x.charCodeAt(index) | | 401 | + | | 402 | + if (charCode > 255) { | | 403 | + throw new TypeError( | | 404 | + 'Cannot convert argument to a ByteString because the character at' + | | 405 | + `index ${index} has a value of ${charCode} which is greater than 255.` | | 406 | + ) | | 407 | + } | 405 | 408 | } | 406 | 409 |
| 407 | 410 | // 3. Return an IDL ByteString value whose length is the | |
Collapse file Copy file name to clipboardExpand all lines: deps/undici/src/package.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | { | 2 | 2 | "name": "undici", | 3 | | - "version": "5.8.1", | | 3 | + "version": "5.8.2", | 4 | 4 | "description": "An HTTP/1.1 client, written from scratch for Node.js", | 5 | 5 | "homepage": "https://undici.nodejs.org", | 6 | 6 | "bugs": { | |
Collapse file Copy file name to clipboardExpand all lines: deps/undici/undici.js +15-7Lines changed: 15 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -737,9 +737,15 @@ var require_util = __commonJS({ | 737 | 737 | } | 738 | 738 | if (!(url instanceof URL)) { | 739 | 739 | const port = url.port != null ? url.port : url.protocol === "https:" ? 443 : 80; | 740 | | - const origin = url.origin != null ? url.origin : `${url.protocol}//${url.hostname}:${port}`; | 741 | | - const path = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`; | 742 | | - url = new URL(path, origin); | | 740 | + let origin = url.origin != null ? url.origin : `${url.protocol}//${url.hostname}:${port}`; | | 741 | + let path = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`; | | 742 | + if (origin.endsWith("/")) { | | 743 | + origin = origin.substring(0, origin.length - 1); | | 744 | + } | | 745 | + if (path && !path.startsWith("/")) { | | 746 | + path = `/${path}`; | | 747 | + } | | 748 | + url = new URL(origin + path); | 743 | 749 | } | 744 | 750 | return url; | 745 | 751 | } | @@ -1281,11 +1287,13 @@ var require_webidl = __commonJS({ | 1281 | 1287 | } | 1282 | 1288 | return String(V); | 1283 | 1289 | }; | 1284 | | - var isLatin1 = /^[\u0000-\u00ff]{0,}$/; | 1285 | 1290 | webidl.converters.ByteString = function(V) { | 1286 | 1291 | const x = webidl.converters.DOMString(V); | 1287 | | - if (!isLatin1.test(x)) { | 1288 | | - throw new TypeError("Argument is not a ByteString"); | | 1292 | + for (let index = 0; index < x.length; index++) { | | 1293 | + const charCode = x.charCodeAt(index); | | 1294 | + if (charCode > 255) { | | 1295 | + throw new TypeError(`Cannot convert argument to a ByteString because the character atindex ${index} has a value of ${charCode} which is greater than 255.`); | | 1296 | + } | 1289 | 1297 | } | 1290 | 1298 | return x; | 1291 | 1299 | }; | @@ -2580,7 +2588,7 @@ var require_request = __commonJS({ | 2580 | 2588 | if (!Number.isFinite(request.contentLength)) { | 2581 | 2589 | throw new InvalidArgumentError("invalid content-length header"); | 2582 | 2590 | } | 2583 | | - } else if (request.contentType === null && key.length === 12 && key.toLowerCase() === "content-type") { | | 2591 | + } else if (request.contentType === null && key.length === 12 && key.toLowerCase() === "content-type" && headerCharRegex.exec(val) === null) { | 2584 | 2592 | request.contentType = val; | 2585 | 2593 | request.headers += `${key}: ${val}\r | 2586 | 2594 | `; | |
|