undici 5.1.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index-fetch.js ADDED
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+
3
+ const Agent = require('./lib/agent')
4
+
5
+ const globalDispatcher = new Agent()
6
+
7
+ const fetchImpl = require('./lib/fetch')
8
+ module.exports.fetch = async function fetch (resource) {
9
+ return fetchImpl.apply(globalDispatcher, arguments)
10
+ }
11
+ module.exports.FormData = require('./lib/fetch/formdata').FormData
12
+ module.exports.Headers = require('./lib/fetch/headers').Headers
13
+ module.exports.Response = require('./lib/fetch/response').Response
14
+ module.exports.Request = require('./lib/fetch/request').Request
@@ -31,6 +31,26 @@ function lowerCaseEntries (headers) {
31
31
  )
32
32
  }
33
33
 
34
+ /**
35
+ * @param {import('../../index').Headers|string[]|Record<string, string>} headers
36
+ * @param {string} key
37
+ */
38
+ function getHeaderByName (headers, key) {
39
+ if (Array.isArray(headers)) {
40
+ for (let i = 0; i < headers.length; i += 2) {
41
+ if (headers[i] === key) {
42
+ return headers[i + 1]
43
+ }
44
+ }
45
+
46
+ return undefined
47
+ } else if (typeof headers.get === 'function') {
48
+ return headers.get(key)
49
+ } else {
50
+ return headers[key]
51
+ }
52
+ }
53
+
34
54
  function matchHeaders (mockDispatch, headers) {
35
55
  if (typeof mockDispatch.headers === 'function') {
36
56
  if (Array.isArray(headers)) { // fetch HeadersList
@@ -51,9 +71,9 @@ function matchHeaders (mockDispatch, headers) {
51
71
  }
52
72
 
53
73
  for (const [matchHeaderName, matchHeaderValue] of Object.entries(mockDispatch.headers)) {
54
- const header = typeof headers.get === 'function' ? headers.get(matchHeaderName) : headers[matchHeaderName]
74
+ const headerValue = getHeaderByName(headers, matchHeaderName)
55
75
 
56
- if (!matchValue(matchHeaderValue, header)) {
76
+ if (!matchValue(matchHeaderValue, headerValue)) {
57
77
  return false
58
78
  }
59
79
  }
@@ -337,5 +357,6 @@ module.exports = {
337
357
  mockDispatch,
338
358
  buildMockDispatch,
339
359
  checkNetConnect,
340
- buildMockOptions
360
+ buildMockOptions,
361
+ getHeaderByName
341
362
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undici",
3
- "version": "5.1.0",
3
+ "version": "5.1.1",
4
4
  "description": "An HTTP/1.1 client, written from scratch for Node.js",
5
5
  "homepage": "https://undici.nodejs.org",
6
6
  "bugs": {
@@ -35,6 +35,7 @@
35
35
  "files": [
36
36
  "*.d.ts",
37
37
  "index.js",
38
+ "index-fetch.js",
38
39
  "lib",
39
40
  "types",
40
41
  "docs"