fetch-har 8.1.3 → 8.1.5

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.
@@ -0,0 +1,5 @@
1
+ {
2
+ "editor.codeActionsOnSave": {
3
+ "source.fixAll": true
4
+ }
5
+ }
package/CHANGELOG.md CHANGED
@@ -1,3 +1,63 @@
1
+ ## <small>8.1.5 (2023-01-23)</small>
2
+
3
+ * fix: support urls with hashes that also have query params (#363) ([7a51342](https://github.com/readmeio/fetch-har/commit/7a51342)), closes [#363](https://github.com/readmeio/fetch-har/issues/363)
4
+ * chore(deps-dev): bumping deps (#362) ([3279246](https://github.com/readmeio/fetch-har/commit/3279246)), closes [#362](https://github.com/readmeio/fetch-har/issues/362)
5
+
6
+
7
+
8
+ ## <small>8.1.4 (2023-01-03)</small>
9
+
10
+ * chore(deps-dev): bump @readme/eslint-config from 10.1.0 to 10.1.1 (#331) ([75de615](https://github.com/readmeio/fetch-har/commit/75de615)), closes [#331](https://github.com/readmeio/fetch-har/issues/331)
11
+ * chore(deps-dev): bump @readme/eslint-config from 10.1.1 to 10.2.0 (#345) ([b791ce3](https://github.com/readmeio/fetch-har/commit/b791ce3)), closes [#345](https://github.com/readmeio/fetch-har/issues/345)
12
+ * chore(deps-dev): bump @readme/eslint-config from 9.0.0 to 10.1.0 (#312) ([27b53b8](https://github.com/readmeio/fetch-har/commit/27b53b8)), closes [#312](https://github.com/readmeio/fetch-har/issues/312)
13
+ * chore(deps-dev): bump @types/chai from 4.3.1 to 4.3.3 (#313) ([cfc65d0](https://github.com/readmeio/fetch-har/commit/cfc65d0)), closes [#313](https://github.com/readmeio/fetch-har/issues/313)
14
+ * chore(deps-dev): bump @types/express from 4.17.13 to 4.17.14 (#323) ([1fec46d](https://github.com/readmeio/fetch-har/commit/1fec46d)), closes [#323](https://github.com/readmeio/fetch-har/issues/323)
15
+ * chore(deps-dev): bump @types/mocha from 10.0.0 to 10.0.1 (#344) ([75d4db7](https://github.com/readmeio/fetch-har/commit/75d4db7)), closes [#344](https://github.com/readmeio/fetch-har/issues/344)
16
+ * chore(deps-dev): bump @types/mocha from 9.1.1 to 10.0.0 (#326) ([36c4b00](https://github.com/readmeio/fetch-har/commit/36c4b00)), closes [#326](https://github.com/readmeio/fetch-har/issues/326)
17
+ * chore(deps-dev): bump @types/node from 18.11.8 to 18.11.10 (#349) ([6479fbf](https://github.com/readmeio/fetch-har/commit/6479fbf)), closes [#349](https://github.com/readmeio/fetch-har/issues/349)
18
+ * chore(deps-dev): bump @types/node from 18.6.1 to 18.6.3 (#309) ([4cce975](https://github.com/readmeio/fetch-har/commit/4cce975)), closes [#309](https://github.com/readmeio/fetch-har/issues/309)
19
+ * chore(deps-dev): bump @types/node from 18.6.3 to 18.7.14 (#315) ([69679ac](https://github.com/readmeio/fetch-har/commit/69679ac)), closes [#315](https://github.com/readmeio/fetch-har/issues/315)
20
+ * chore(deps-dev): bump @types/node from 18.7.14 to 18.7.23 (#324) ([8c0c037](https://github.com/readmeio/fetch-har/commit/8c0c037)), closes [#324](https://github.com/readmeio/fetch-har/issues/324)
21
+ * chore(deps-dev): bump @types/node from 18.7.23 to 18.8.0 (#330) ([0174e1d](https://github.com/readmeio/fetch-har/commit/0174e1d)), closes [#330](https://github.com/readmeio/fetch-har/issues/330)
22
+ * chore(deps-dev): bump @types/node from 18.8.0 to 18.11.8 (#335) ([5a602b3](https://github.com/readmeio/fetch-har/commit/5a602b3)), closes [#335](https://github.com/readmeio/fetch-har/issues/335)
23
+ * chore(deps-dev): bump chai from 4.3.6 to 4.3.7 (#348) ([b427f19](https://github.com/readmeio/fetch-har/commit/b427f19)), closes [#348](https://github.com/readmeio/fetch-har/issues/348)
24
+ * chore(deps-dev): bump eslint from 8.20.0 to 8.23.0 (#318) ([5d6293b](https://github.com/readmeio/fetch-har/commit/5d6293b)), closes [#318](https://github.com/readmeio/fetch-har/issues/318)
25
+ * chore(deps-dev): bump eslint from 8.23.0 to 8.24.0 (#325) ([033eeec](https://github.com/readmeio/fetch-har/commit/033eeec)), closes [#325](https://github.com/readmeio/fetch-har/issues/325)
26
+ * chore(deps-dev): bump eslint from 8.24.0 to 8.26.0 (#339) ([8806ab8](https://github.com/readmeio/fetch-har/commit/8806ab8)), closes [#339](https://github.com/readmeio/fetch-har/issues/339)
27
+ * chore(deps-dev): bump eslint from 8.26.0 to 8.28.0 (#350) ([3440e1c](https://github.com/readmeio/fetch-har/commit/3440e1c)), closes [#350](https://github.com/readmeio/fetch-har/issues/350)
28
+ * chore(deps-dev): bump express from 4.18.1 to 4.18.2 (#338) ([acdc8ac](https://github.com/readmeio/fetch-har/commit/acdc8ac)), closes [#338](https://github.com/readmeio/fetch-har/issues/338)
29
+ * chore(deps-dev): bump mocha from 10.0.0 to 10.1.0 (#336) ([9e91790](https://github.com/readmeio/fetch-har/commit/9e91790)), closes [#336](https://github.com/readmeio/fetch-har/issues/336)
30
+ * chore(deps-dev): bump prettier from 2.7.1 to 2.8.0 (#347) ([22ce3c9](https://github.com/readmeio/fetch-har/commit/22ce3c9)), closes [#347](https://github.com/readmeio/fetch-har/issues/347)
31
+ * chore(deps-dev): bump typescript from 4.7.4 to 4.8.2 (#316) ([a5819c1](https://github.com/readmeio/fetch-har/commit/a5819c1)), closes [#316](https://github.com/readmeio/fetch-har/issues/316)
32
+ * chore(deps-dev): bump typescript from 4.8.2 to 4.8.4 (#327) ([2e1fdf1](https://github.com/readmeio/fetch-har/commit/2e1fdf1)), closes [#327](https://github.com/readmeio/fetch-har/issues/327)
33
+ * chore(deps-dev): bump typescript from 4.8.4 to 4.9.3 (#346) ([afa6122](https://github.com/readmeio/fetch-har/commit/afa6122)), closes [#346](https://github.com/readmeio/fetch-har/issues/346)
34
+ * chore(deps-dev): bump undici from 5.10.0 to 5.11.0 (#332) ([a020b27](https://github.com/readmeio/fetch-har/commit/a020b27)), closes [#332](https://github.com/readmeio/fetch-har/issues/332)
35
+ * chore(deps-dev): bump undici from 5.11.0 to 5.12.0 (#337) ([e4e3daf](https://github.com/readmeio/fetch-har/commit/e4e3daf)), closes [#337](https://github.com/readmeio/fetch-har/issues/337)
36
+ * chore(deps-dev): bump undici from 5.12.0 to 5.13.0 (#351) ([2f1da07](https://github.com/readmeio/fetch-har/commit/2f1da07)), closes [#351](https://github.com/readmeio/fetch-har/issues/351)
37
+ * chore(deps-dev): bump undici from 5.8.0 to 5.8.2 (#310) ([09a5241](https://github.com/readmeio/fetch-har/commit/09a5241)), closes [#310](https://github.com/readmeio/fetch-har/issues/310)
38
+ * chore(deps-dev): bump undici from 5.8.2 to 5.10.0 (#314) ([ad16183](https://github.com/readmeio/fetch-har/commit/ad16183)), closes [#314](https://github.com/readmeio/fetch-har/issues/314)
39
+ * chore(deps): bump @types/har-format from 1.2.8 to 1.2.9 (#322) ([4746a42](https://github.com/readmeio/fetch-har/commit/4746a42)), closes [#322](https://github.com/readmeio/fetch-har/issues/322)
40
+ * chore(deps): bump @types/har-format from 1.2.9 to 1.2.10 (#352) ([df4506a](https://github.com/readmeio/fetch-har/commit/df4506a)), closes [#352](https://github.com/readmeio/fetch-har/issues/352)
41
+ * chore(deps): bump actions/cache from 3.0.10 to 3.0.11 (#334) ([b4b9a7c](https://github.com/readmeio/fetch-har/commit/b4b9a7c)), closes [#334](https://github.com/readmeio/fetch-har/issues/334)
42
+ * chore(deps): bump actions/cache from 3.0.5 to 3.0.8 (#311) ([011f9d4](https://github.com/readmeio/fetch-har/commit/011f9d4)), closes [#311](https://github.com/readmeio/fetch-har/issues/311)
43
+ * chore(deps): bump actions/cache from 3.0.8 to 3.0.9 (#320) ([441c2a6](https://github.com/readmeio/fetch-har/commit/441c2a6)), closes [#320](https://github.com/readmeio/fetch-har/issues/320)
44
+ * chore(deps): bump actions/cache from 3.0.9 to 3.0.10 (#329) ([0d9bc07](https://github.com/readmeio/fetch-har/commit/0d9bc07)), closes [#329](https://github.com/readmeio/fetch-har/issues/329)
45
+ * chore(deps): bump decode-uri-component from 0.2.0 to 0.2.2 (#353) ([b987538](https://github.com/readmeio/fetch-har/commit/b987538)), closes [#353](https://github.com/readmeio/fetch-har/issues/353)
46
+ * chore(deps): bump engine.io and socket.io (#343) ([5e0451a](https://github.com/readmeio/fetch-har/commit/5e0451a)), closes [#343](https://github.com/readmeio/fetch-har/issues/343)
47
+ * chore(deps): bump formdata-node from 4.3.3 to 4.4.1 (#319) ([31ab620](https://github.com/readmeio/fetch-har/commit/31ab620)), closes [#319](https://github.com/readmeio/fetch-har/issues/319)
48
+ * chore(deps): bump loader-utils from 1.4.0 to 1.4.1 (#340) ([e90b650](https://github.com/readmeio/fetch-har/commit/e90b650)), closes [#340](https://github.com/readmeio/fetch-har/issues/340)
49
+ * chore(deps): bump loader-utils from 1.4.1 to 1.4.2 (#342) ([ca2e6d2](https://github.com/readmeio/fetch-har/commit/ca2e6d2)), closes [#342](https://github.com/readmeio/fetch-har/issues/342)
50
+ * chore(deps): bump socket.io-parser from 4.0.4 to 4.0.5 (#341) ([97cbd5b](https://github.com/readmeio/fetch-har/commit/97cbd5b)), closes [#341](https://github.com/readmeio/fetch-har/issues/341)
51
+ * chore(deps): bumping deps ([6636acd](https://github.com/readmeio/fetch-har/commit/6636acd))
52
+ * ci: formdata-node is esm only now so we cant use it ([b9b0b47](https://github.com/readmeio/fetch-har/commit/b9b0b47))
53
+ * ci: running unit tests on node 19 (#333) ([6f936da](https://github.com/readmeio/fetch-har/commit/6f936da)), closes [#333](https://github.com/readmeio/fetch-har/issues/333)
54
+ * ci: simplifying ci dep caching ([78a5f34](https://github.com/readmeio/fetch-har/commit/78a5f34))
55
+ * ci: stop testing on node 19 until it hits LTS ([864a10b](https://github.com/readmeio/fetch-har/commit/864a10b))
56
+ * ci: temp-dir is esm-only now ([15e96a0](https://github.com/readmeio/fetch-har/commit/15e96a0))
57
+ * ci: timing out browser tests at 5mins ([c53c161](https://github.com/readmeio/fetch-har/commit/c53c161))
58
+
59
+
60
+
1
61
  ## <small>8.1.3 (2022-07-29)</small>
2
62
 
3
63
  * chore: clenaing up some lengthy test comments ([7f797af](https://github.com/readmeio/fetch-har/commit/7f797af))
package/dist/index.d.ts CHANGED
@@ -1,9 +1,22 @@
1
1
  /// <reference types="node" />
2
2
  import type { Har } from 'har-format';
3
- export declare type FetchHAROptions = {
3
+ interface RequestInitWithDuplex extends RequestInit {
4
+ /**
5
+ * `RequestInit#duplex` does not yet exist in the TS `lib.dom.d.ts` definition yet the native
6
+ * fetch implementation in Node 18+, `undici`, requires it for certain POST payloads.
7
+ *
8
+ * @see {@link https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1483}
9
+ * @see {@link https://github.com/nodejs/node/issues/46221}
10
+ * @see {@link https://fetch.spec.whatwg.org/#request-class}
11
+ * @see {@link https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts}
12
+ */
13
+ duplex?: 'half';
14
+ }
15
+ export interface FetchHAROptions {
4
16
  userAgent?: string;
5
17
  files?: Record<string, Blob | Buffer>;
6
18
  multipartEncoder?: any;
7
- init?: RequestInit;
8
- };
19
+ init?: RequestInitWithDuplex;
20
+ }
9
21
  export default function fetchHAR(har: Har, opts?: FetchHAROptions): Promise<Response>;
22
+ export {};
package/dist/index.js CHANGED
@@ -11,8 +11,8 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  exports.__esModule = true;
14
- var readable_stream_1 = require("readable-stream");
15
14
  var data_urls_1 = require("@readme/data-urls");
15
+ var readable_stream_1 = require("readable-stream");
16
16
  if (!globalThis.Blob) {
17
17
  try {
18
18
  // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-extraneous-dependencies
@@ -101,6 +101,7 @@ function fetchHAR(har, opts) {
101
101
  var request = har.log.entries[0].request;
102
102
  var url = request.url;
103
103
  var querystring = '';
104
+ var shouldSetDuplex = false;
104
105
  var options = __assign(__assign({}, (opts.init ? opts.init : {})), { method: request.method });
105
106
  if (!options.headers) {
106
107
  options.headers = new Headers();
@@ -260,6 +261,7 @@ function fetchHAR(har, opts) {
260
261
  });
261
262
  // @ts-expect-error "Property 'from' does not exist on type 'typeof Readable'." but it does!
262
263
  options.body = readable_stream_1.Readable.from(encoder_1);
264
+ shouldSetDuplex = true;
263
265
  }
264
266
  else {
265
267
  options.body = form_1;
@@ -300,6 +302,7 @@ function fetchHAR(har, opts) {
300
302
  else {
301
303
  // @ts-expect-error "Property 'from' does not exist on type 'typeof Readable'." but it does!
302
304
  options.body = readable_stream_1.Readable.from(fileContents.stream());
305
+ shouldSetDuplex = true;
303
306
  // Supplying a polyfilled `File` stream into `Request.body` doesn't automatically
304
307
  // add `Content-Length`.
305
308
  if (!headers.has('content-length')) {
@@ -315,11 +318,27 @@ function fetchHAR(har, opts) {
315
318
  options.body = request.postData.text;
316
319
  }
317
320
  }
321
+ /**
322
+ * The fetch spec, which Node 18+ strictly abides by, now requires that `duplex` be sent with
323
+ * requests that have payloads.
324
+ *
325
+ * As `RequestInit#duplex` isn't supported by any browsers, or even mentioned on MDN, we aren't
326
+ * sending it in browser environments. This work is purely to support Node 18+ and `undici`
327
+ * environments.
328
+ *
329
+ * @see {@link https://github.com/nodejs/node/issues/46221}
330
+ * @see {@link https://github.com/whatwg/fetch/pull/1457}
331
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request}
332
+ */
333
+ if (shouldSetDuplex && !isBrowser()) {
334
+ options.duplex = 'half';
335
+ }
318
336
  }
319
337
  // We automaticaly assume that the HAR that we have already has query parameters encoded within
320
338
  // it so we do **not** use the `URLSearchParams` API here for composing the query string.
339
+ var requestURL = url;
321
340
  if ('queryString' in request && request.queryString.length) {
322
- var urlObj = new URL(url);
341
+ var urlObj = new URL(requestURL);
323
342
  var queryParams_1 = Array.from(urlObj.searchParams).map(function (_a) {
324
343
  var k = _a[0], v = _a[1];
325
344
  return "".concat(k, "=").concat(v);
@@ -328,11 +347,21 @@ function fetchHAR(har, opts) {
328
347
  queryParams_1.push("".concat(q.name, "=").concat(q.value));
329
348
  });
330
349
  querystring = queryParams_1.join('&');
350
+ // Because anchor hashes before query strings will prevent query strings from being delivered
351
+ // we need to pop them off and re-add them after.
352
+ if (urlObj.hash) {
353
+ var urlWithoutHashes = requestURL.replace(urlObj.hash, '');
354
+ requestURL = "".concat(urlWithoutHashes.split('?')[0]).concat(querystring ? "?".concat(querystring) : '');
355
+ requestURL += urlObj.hash;
356
+ }
357
+ else {
358
+ requestURL = "".concat(requestURL.split('?')[0]).concat(querystring ? "?".concat(querystring) : '');
359
+ }
331
360
  }
332
361
  if (opts.userAgent) {
333
362
  headers.append('User-Agent', opts.userAgent);
334
363
  }
335
364
  options.headers = headers;
336
- return fetch("".concat(url.split('?')[0]).concat(querystring ? "?".concat(querystring) : ''), options);
365
+ return fetch(requestURL, options);
337
366
  }
338
367
  exports["default"] = fetchHAR;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fetch-har",
3
- "version": "8.1.3",
3
+ "version": "8.1.5",
4
4
  "description": "Make a fetch request from a HAR definition",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -40,16 +40,16 @@
40
40
  "devDependencies": {
41
41
  "@jsdevtools/host-environment": "^2.1.2",
42
42
  "@jsdevtools/karma-config": "^3.1.7",
43
- "@readme/eslint-config": "^9.0.0",
43
+ "@readme/eslint-config": "^10.4.5",
44
44
  "@types/chai": "^4.3.1",
45
- "@types/express": "^4.17.13",
46
- "@types/mocha": "^9.1.1",
45
+ "@types/express": "^4.17.15",
46
+ "@types/mocha": "^10.0.0",
47
47
  "@types/multer": "^1.4.7",
48
- "@types/node": "^18.0.0",
49
- "@types/readable-stream": "^2.3.13",
48
+ "@types/node": "^18.11.18",
49
+ "@types/readable-stream": "^2.3.15",
50
50
  "chai": "^4.3.4",
51
51
  "datauri": "^4.1.0",
52
- "eslint": "^8.14.0",
52
+ "eslint": "^8.32.0",
53
53
  "express": "^4.18.1",
54
54
  "fetch-mock": "^9.11.0",
55
55
  "form-data": "^4.0.0",
@@ -57,17 +57,17 @@
57
57
  "formdata-node": "^4.3.2",
58
58
  "har-examples": "^3.1.1",
59
59
  "isomorphic-fetch": "^3.0.0",
60
- "mocha": "^10.0.0",
60
+ "mocha": "^10.2.0",
61
61
  "multer": "^1.4.5-lts.1",
62
- "nock": "^13.2.4",
62
+ "nock": "^13.3.0",
63
63
  "node-fetch": "^2.6.0",
64
64
  "nyc": "^15.1.0",
65
- "prettier": "^2.6.2",
65
+ "prettier": "^2.8.3",
66
66
  "temp-dir": "^2.0.0",
67
67
  "ts-loader": "^8.4.0",
68
68
  "ts-node": "^10.7.0",
69
- "typescript": "^4.6.3",
70
- "undici": "^5.0.0",
69
+ "typescript": "^4.9.4",
70
+ "undici": "^5.16.0",
71
71
  "webpack": "^4.46.0"
72
72
  },
73
73
  "browserslist": [
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
- import type { Har } from 'har-format';
2
1
  import type { DataURL as npmDataURL } from '@readme/data-urls';
3
- import { Readable } from 'readable-stream';
2
+ import type { Har } from 'har-format';
3
+
4
4
  import { parse as parseDataUrl } from '@readme/data-urls';
5
+ import { Readable } from 'readable-stream';
5
6
 
6
7
  if (!globalThis.Blob) {
7
8
  try {
@@ -36,12 +37,25 @@ if (!globalThis.FormData) {
36
37
  }
37
38
  }
38
39
 
39
- export type FetchHAROptions = {
40
+ interface RequestInitWithDuplex extends RequestInit {
41
+ /**
42
+ * `RequestInit#duplex` does not yet exist in the TS `lib.dom.d.ts` definition yet the native
43
+ * fetch implementation in Node 18+, `undici`, requires it for certain POST payloads.
44
+ *
45
+ * @see {@link https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1483}
46
+ * @see {@link https://github.com/nodejs/node/issues/46221}
47
+ * @see {@link https://fetch.spec.whatwg.org/#request-class}
48
+ * @see {@link https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts}
49
+ */
50
+ duplex?: 'half';
51
+ }
52
+
53
+ export interface FetchHAROptions {
40
54
  userAgent?: string;
41
55
  files?: Record<string, Blob | Buffer>;
42
56
  multipartEncoder?: any; // form-data-encoder
43
- init?: RequestInit;
44
- };
57
+ init?: RequestInitWithDuplex;
58
+ }
45
59
 
46
60
  type DataURL = npmDataURL & {
47
61
  // `parse-data-url` doesn't explicitly support `name` in data URLs but if it's there it'll be
@@ -116,8 +130,9 @@ export default function fetchHAR(har: Har, opts: FetchHAROptions = {}) {
116
130
  const { request } = har.log.entries[0];
117
131
  const { url } = request;
118
132
  let querystring = '';
133
+ let shouldSetDuplex = false;
119
134
 
120
- const options: RequestInit = {
135
+ const options: RequestInitWithDuplex = {
121
136
  // If we have custom options for the `Request` API we need to add them in here now before we
122
137
  // fill it in with everything we need from the HAR.
123
138
  ...(opts.init ? opts.init : {}),
@@ -308,6 +323,7 @@ export default function fetchHAR(har: Har, opts: FetchHAROptions = {}) {
308
323
 
309
324
  // @ts-expect-error "Property 'from' does not exist on type 'typeof Readable'." but it does!
310
325
  options.body = Readable.from(encoder);
326
+ shouldSetDuplex = true;
311
327
  } else {
312
328
  options.body = form;
313
329
  }
@@ -346,6 +362,7 @@ export default function fetchHAR(har: Har, opts: FetchHAROptions = {}) {
346
362
  } else {
347
363
  // @ts-expect-error "Property 'from' does not exist on type 'typeof Readable'." but it does!
348
364
  options.body = Readable.from((fileContents as File).stream());
365
+ shouldSetDuplex = true;
349
366
 
350
367
  // Supplying a polyfilled `File` stream into `Request.body` doesn't automatically
351
368
  // add `Content-Length`.
@@ -363,12 +380,29 @@ export default function fetchHAR(har: Har, opts: FetchHAROptions = {}) {
363
380
  options.body = request.postData.text;
364
381
  }
365
382
  }
383
+
384
+ /**
385
+ * The fetch spec, which Node 18+ strictly abides by, now requires that `duplex` be sent with
386
+ * requests that have payloads.
387
+ *
388
+ * As `RequestInit#duplex` isn't supported by any browsers, or even mentioned on MDN, we aren't
389
+ * sending it in browser environments. This work is purely to support Node 18+ and `undici`
390
+ * environments.
391
+ *
392
+ * @see {@link https://github.com/nodejs/node/issues/46221}
393
+ * @see {@link https://github.com/whatwg/fetch/pull/1457}
394
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request}
395
+ */
396
+ if (shouldSetDuplex && !isBrowser()) {
397
+ options.duplex = 'half';
398
+ }
366
399
  }
367
400
 
368
401
  // We automaticaly assume that the HAR that we have already has query parameters encoded within
369
402
  // it so we do **not** use the `URLSearchParams` API here for composing the query string.
403
+ let requestURL = url;
370
404
  if ('queryString' in request && request.queryString.length) {
371
- const urlObj = new URL(url);
405
+ const urlObj = new URL(requestURL);
372
406
 
373
407
  const queryParams = Array.from(urlObj.searchParams).map(([k, v]) => `${k}=${v}`);
374
408
  request.queryString.forEach(q => {
@@ -376,6 +410,16 @@ export default function fetchHAR(har: Har, opts: FetchHAROptions = {}) {
376
410
  });
377
411
 
378
412
  querystring = queryParams.join('&');
413
+
414
+ // Because anchor hashes before query strings will prevent query strings from being delivered
415
+ // we need to pop them off and re-add them after.
416
+ if (urlObj.hash) {
417
+ const urlWithoutHashes = requestURL.replace(urlObj.hash, '');
418
+ requestURL = `${urlWithoutHashes.split('?')[0]}${querystring ? `?${querystring}` : ''}`;
419
+ requestURL += urlObj.hash;
420
+ } else {
421
+ requestURL = `${requestURL.split('?')[0]}${querystring ? `?${querystring}` : ''}`;
422
+ }
379
423
  }
380
424
 
381
425
  if (opts.userAgent) {
@@ -384,5 +428,5 @@ export default function fetchHAR(har: Har, opts: FetchHAROptions = {}) {
384
428
 
385
429
  options.headers = headers;
386
430
 
387
- return fetch(`${url.split('?')[0]}${querystring ? `?${querystring}` : ''}`, options);
431
+ return fetch(requestURL, options);
388
432
  }