msw 2.12.11 → 2.12.13

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.
Files changed (92) hide show
  1. package/config/scripts/postinstall.js +2 -2
  2. package/lib/core/{HttpResponse-Cw4ELwIN.d.mts → HttpResponse-Be4eT3x6.d.mts} +8 -2
  3. package/lib/core/{HttpResponse-CVs3ngx3.d.ts → HttpResponse-Dj6ibgFJ.d.ts} +8 -2
  4. package/lib/core/HttpResponse.d.mts +1 -1
  5. package/lib/core/HttpResponse.d.ts +1 -1
  6. package/lib/core/HttpResponse.js +53 -11
  7. package/lib/core/HttpResponse.js.map +1 -1
  8. package/lib/core/HttpResponse.mjs +53 -11
  9. package/lib/core/HttpResponse.mjs.map +1 -1
  10. package/lib/core/SetupApi.d.mts +1 -1
  11. package/lib/core/SetupApi.d.ts +1 -1
  12. package/lib/core/getResponse.d.mts +1 -1
  13. package/lib/core/getResponse.d.ts +1 -1
  14. package/lib/core/graphql.d.mts +1 -1
  15. package/lib/core/graphql.d.ts +1 -1
  16. package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
  17. package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
  18. package/lib/core/handlers/GraphQLHandler.js +29 -1
  19. package/lib/core/handlers/GraphQLHandler.js.map +1 -1
  20. package/lib/core/handlers/GraphQLHandler.mjs +29 -1
  21. package/lib/core/handlers/GraphQLHandler.mjs.map +1 -1
  22. package/lib/core/handlers/HttpHandler.d.mts +1 -1
  23. package/lib/core/handlers/HttpHandler.d.ts +1 -1
  24. package/lib/core/handlers/RequestHandler.d.mts +1 -1
  25. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  26. package/lib/core/handlers/RequestHandler.js.map +1 -1
  27. package/lib/core/handlers/RequestHandler.mjs.map +1 -1
  28. package/lib/core/http.d.mts +1 -1
  29. package/lib/core/http.d.ts +1 -1
  30. package/lib/core/index.d.mts +3 -3
  31. package/lib/core/index.d.ts +3 -3
  32. package/lib/core/index.js +6 -4
  33. package/lib/core/index.js.map +1 -1
  34. package/lib/core/index.mjs +8 -3
  35. package/lib/core/index.mjs.map +1 -1
  36. package/lib/core/passthrough.d.mts +1 -1
  37. package/lib/core/passthrough.d.ts +1 -1
  38. package/lib/core/sse.d.mts +1 -1
  39. package/lib/core/sse.d.ts +1 -1
  40. package/lib/core/sse.js +1 -1
  41. package/lib/core/sse.js.map +1 -1
  42. package/lib/core/sse.mjs +1 -1
  43. package/lib/core/sse.mjs.map +1 -1
  44. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  45. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  46. package/lib/core/utils/executeHandlers.d.mts +1 -1
  47. package/lib/core/utils/executeHandlers.d.ts +1 -1
  48. package/lib/core/utils/handleRequest.d.mts +1 -1
  49. package/lib/core/utils/handleRequest.d.ts +1 -1
  50. package/lib/core/utils/internal/isHandlerKind.d.mts +1 -1
  51. package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
  52. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
  53. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
  54. package/lib/core/utils/internal/parseGraphQLRequest.js +1 -1
  55. package/lib/core/utils/internal/parseGraphQLRequest.js.map +1 -1
  56. package/lib/core/utils/internal/parseGraphQLRequest.mjs +1 -1
  57. package/lib/core/utils/internal/parseGraphQLRequest.mjs.map +1 -1
  58. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  59. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  60. package/lib/core/utils/internal/parseMultipartData.js +3 -1
  61. package/lib/core/utils/internal/parseMultipartData.js.map +1 -1
  62. package/lib/core/utils/internal/parseMultipartData.mjs +3 -1
  63. package/lib/core/utils/internal/parseMultipartData.mjs.map +1 -1
  64. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  65. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  66. package/lib/core/utils/request/getAllAcceptedMimeTypes.d.mts +14 -0
  67. package/lib/core/utils/request/getAllAcceptedMimeTypes.d.ts +14 -0
  68. package/lib/core/utils/request/getAllAcceptedMimeTypes.js +61 -0
  69. package/lib/core/utils/request/getAllAcceptedMimeTypes.js.map +1 -0
  70. package/lib/core/utils/request/getAllAcceptedMimeTypes.mjs +41 -0
  71. package/lib/core/utils/request/getAllAcceptedMimeTypes.mjs.map +1 -0
  72. package/lib/core/ws/WebSocketIndexedDBClientStore.js +1 -1
  73. package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -1
  74. package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +1 -1
  75. package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -1
  76. package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
  77. package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
  78. package/lib/iife/index.js +262 -159
  79. package/lib/iife/index.js.map +1 -1
  80. package/lib/mockServiceWorker.js +1 -1
  81. package/package.json +2 -2
  82. package/src/core/HttpResponse.test.ts +25 -9
  83. package/src/core/HttpResponse.ts +62 -10
  84. package/src/core/handlers/GraphQLHandler.ts +54 -2
  85. package/src/core/handlers/RequestHandler.ts +1 -1
  86. package/src/core/index.ts +8 -3
  87. package/src/core/sse.ts +1 -1
  88. package/src/core/utils/internal/parseGraphQLRequest.ts +1 -1
  89. package/src/core/utils/internal/parseMultipartData.ts +3 -1
  90. package/src/core/utils/request/getAllAcceptedMimeTypes.test.ts +86 -0
  91. package/src/core/utils/request/getAllAcceptedMimeTypes.ts +70 -0
  92. package/src/core/ws/WebSocketIndexedDBClientStore.ts +1 -2
package/lib/iife/index.js CHANGED
@@ -14074,15 +14074,10 @@ ${operationTypes.join("\n")}
14074
14074
  HttpHandler: () => HttpHandler,
14075
14075
  HttpMethods: () => HttpMethods,
14076
14076
  HttpResponse: () => HttpResponse,
14077
- MAX_SERVER_RESPONSE_TIME: () => MAX_SERVER_RESPONSE_TIME,
14078
- MIN_SERVER_RESPONSE_TIME: () => MIN_SERVER_RESPONSE_TIME,
14079
- NODE_SERVER_RESPONSE_TIME: () => NODE_SERVER_RESPONSE_TIME,
14080
14077
  RequestHandler: () => RequestHandler,
14081
- SET_TIMEOUT_MAX_ALLOWED_INT: () => SET_TIMEOUT_MAX_ALLOWED_INT,
14082
14078
  SetupApi: () => SetupApi,
14083
14079
  SetupWorkerApi: () => SetupWorkerApi,
14084
14080
  WebSocketHandler: () => WebSocketHandler,
14085
- bodyType: () => bodyType,
14086
14081
  bypass: () => bypass,
14087
14082
  cleanUrl: () => cleanUrl,
14088
14083
  delay: () => delay,
@@ -19138,7 +19133,9 @@ ${operationTypes.join("\n")}
19138
19133
  if (!boundary) {
19139
19134
  return void 0;
19140
19135
  }
19141
- const boundaryRegExp = new RegExp(`--+${boundary}`);
19136
+ const boundaryRegExp = new RegExp(
19137
+ `--+${boundary.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`
19138
+ );
19142
19139
  const fields = data.split(boundaryRegExp).filter((chunk) => chunk.startsWith("\r\n") && chunk.endsWith("\r\n")).map((chunk) => chunk.trimStart().replace(/\r\n$/, ""));
19143
19140
  if (!fields.length) {
19144
19141
  return void 0;
@@ -19196,7 +19193,7 @@ ${operationTypes.join("\n")}
19196
19193
  let target = operations;
19197
19194
  for (const path of paths) {
19198
19195
  if (!(path in target)) {
19199
- throw new Error(`Property '${paths}' is not in operations.`);
19196
+ throw new Error(`Property '${path}' is not in operations.`);
19200
19197
  }
19201
19198
  target = target[path];
19202
19199
  }
@@ -19284,6 +19281,236 @@ ${operationTypes.join("\n")}
19284
19281
  };
19285
19282
  }
19286
19283
 
19284
+ // src/core/utils/HttpResponse/decorators.ts
19285
+ var { message: message3 } = statuses_default;
19286
+ var kSetCookie = Symbol("kSetCookie");
19287
+ function normalizeResponseInit(init = {}) {
19288
+ const status = init?.status || 200;
19289
+ const statusText = init?.statusText || message3[status] || "";
19290
+ const headers = new Headers(init?.headers);
19291
+ return {
19292
+ ...init,
19293
+ headers,
19294
+ status,
19295
+ statusText
19296
+ };
19297
+ }
19298
+ function decorateResponse(response, init) {
19299
+ if (init.type) {
19300
+ Object.defineProperty(response, "type", {
19301
+ value: init.type,
19302
+ enumerable: true,
19303
+ writable: false
19304
+ });
19305
+ }
19306
+ const responseCookies = init.headers.get("set-cookie");
19307
+ if (responseCookies) {
19308
+ Object.defineProperty(response, kSetCookie, {
19309
+ value: responseCookies,
19310
+ enumerable: false,
19311
+ writable: false
19312
+ });
19313
+ if (typeof document !== "undefined") {
19314
+ const responseCookiePairs = Headers2.prototype.getSetCookie.call(
19315
+ init.headers
19316
+ );
19317
+ for (const cookieString of responseCookiePairs) {
19318
+ document.cookie = cookieString;
19319
+ }
19320
+ }
19321
+ }
19322
+ return response;
19323
+ }
19324
+
19325
+ // src/core/HttpResponse.ts
19326
+ var bodyType = Symbol("bodyType");
19327
+ var kDefaultContentType = Symbol.for("kDefaultContentType");
19328
+ var HttpResponse = class _HttpResponse extends FetchResponse {
19329
+ [bodyType] = null;
19330
+ constructor(body, init) {
19331
+ const responseInit = normalizeResponseInit(init);
19332
+ super(body, responseInit);
19333
+ decorateResponse(this, responseInit);
19334
+ }
19335
+ static error() {
19336
+ return super.error();
19337
+ }
19338
+ /**
19339
+ * Create a `Response` with a `Content-Type: "text/plain"` body.
19340
+ * @example
19341
+ * HttpResponse.text('hello world')
19342
+ * HttpResponse.text('Error', { status: 500 })
19343
+ */
19344
+ static text(body, init) {
19345
+ const responseInit = normalizeResponseInit(init);
19346
+ const hasExplicitContentType = responseInit.headers.has("Content-Type");
19347
+ if (!hasExplicitContentType) {
19348
+ responseInit.headers.set("Content-Type", "text/plain");
19349
+ }
19350
+ if (!responseInit.headers.has("Content-Length")) {
19351
+ responseInit.headers.set(
19352
+ "Content-Length",
19353
+ body ? new Blob([body]).size.toString() : "0"
19354
+ );
19355
+ }
19356
+ const response = new _HttpResponse(body, responseInit);
19357
+ if (!hasExplicitContentType) {
19358
+ Object.defineProperty(response, kDefaultContentType, {
19359
+ value: true,
19360
+ enumerable: false
19361
+ });
19362
+ }
19363
+ return response;
19364
+ }
19365
+ /**
19366
+ * Create a `Response` with a `Content-Type: "application/json"` body.
19367
+ * @example
19368
+ * HttpResponse.json({ firstName: 'John' })
19369
+ * HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })
19370
+ */
19371
+ static json(body, init) {
19372
+ const responseInit = normalizeResponseInit(init);
19373
+ const hasExplicitContentType = responseInit.headers.has("Content-Type");
19374
+ if (!hasExplicitContentType) {
19375
+ responseInit.headers.set("Content-Type", "application/json");
19376
+ }
19377
+ const responseText = JSON.stringify(body);
19378
+ if (!responseInit.headers.has("Content-Length")) {
19379
+ responseInit.headers.set(
19380
+ "Content-Length",
19381
+ responseText ? new Blob([responseText]).size.toString() : "0"
19382
+ );
19383
+ }
19384
+ const response = new _HttpResponse(responseText, responseInit);
19385
+ if (!hasExplicitContentType) {
19386
+ Object.defineProperty(response, kDefaultContentType, {
19387
+ value: true,
19388
+ enumerable: false
19389
+ });
19390
+ }
19391
+ return response;
19392
+ }
19393
+ /**
19394
+ * Create a `Response` with a `Content-Type: "application/xml"` body.
19395
+ * @example
19396
+ * HttpResponse.xml(`<user name="John" />`)
19397
+ * HttpResponse.xml(`<article id="abc-123" />`, { status: 201 })
19398
+ */
19399
+ static xml(body, init) {
19400
+ const responseInit = normalizeResponseInit(init);
19401
+ const hasExplicitContentType = responseInit.headers.has("Content-Type");
19402
+ if (!hasExplicitContentType) {
19403
+ responseInit.headers.set("Content-Type", "text/xml");
19404
+ }
19405
+ const response = new _HttpResponse(body, responseInit);
19406
+ if (!hasExplicitContentType) {
19407
+ Object.defineProperty(response, kDefaultContentType, {
19408
+ value: true,
19409
+ enumerable: false
19410
+ });
19411
+ }
19412
+ return response;
19413
+ }
19414
+ /**
19415
+ * Create a `Response` with a `Content-Type: "text/html"` body.
19416
+ * @example
19417
+ * HttpResponse.html(`<p class="author">Jane Doe</p>`)
19418
+ * HttpResponse.html(`<main id="abc-123">Main text</main>`, { status: 201 })
19419
+ */
19420
+ static html(body, init) {
19421
+ const responseInit = normalizeResponseInit(init);
19422
+ const hasExplicitContentType = responseInit.headers.has("Content-Type");
19423
+ if (!hasExplicitContentType) {
19424
+ responseInit.headers.set("Content-Type", "text/html");
19425
+ }
19426
+ const response = new _HttpResponse(body, responseInit);
19427
+ if (!hasExplicitContentType) {
19428
+ Object.defineProperty(response, kDefaultContentType, {
19429
+ value: true,
19430
+ enumerable: false
19431
+ });
19432
+ }
19433
+ return response;
19434
+ }
19435
+ /**
19436
+ * Create a `Response` with an `ArrayBuffer` body.
19437
+ * @example
19438
+ * const buffer = new ArrayBuffer(3)
19439
+ * const view = new Uint8Array(buffer)
19440
+ * view.set([1, 2, 3])
19441
+ *
19442
+ * HttpResponse.arrayBuffer(buffer)
19443
+ */
19444
+ static arrayBuffer(body, init) {
19445
+ const responseInit = normalizeResponseInit(init);
19446
+ const hasExplicitContentType = responseInit.headers.has("Content-Type");
19447
+ if (!hasExplicitContentType) {
19448
+ responseInit.headers.set("Content-Type", "application/octet-stream");
19449
+ }
19450
+ if (body && !responseInit.headers.has("Content-Length")) {
19451
+ responseInit.headers.set("Content-Length", body.byteLength.toString());
19452
+ }
19453
+ const response = new _HttpResponse(body, responseInit);
19454
+ if (!hasExplicitContentType) {
19455
+ Object.defineProperty(response, kDefaultContentType, {
19456
+ value: true,
19457
+ enumerable: false
19458
+ });
19459
+ }
19460
+ return response;
19461
+ }
19462
+ /**
19463
+ * Create a `Response` with a `FormData` body.
19464
+ * @example
19465
+ * const data = new FormData()
19466
+ * data.set('name', 'Alice')
19467
+ *
19468
+ * HttpResponse.formData(data)
19469
+ */
19470
+ static formData(body, init) {
19471
+ return new _HttpResponse(body, normalizeResponseInit(init));
19472
+ }
19473
+ };
19474
+
19475
+ // src/core/utils/request/getAllAcceptedMimeTypes.ts
19476
+ function getAllAcceptedMimeTypes(acceptHeader) {
19477
+ if (acceptHeader == null) {
19478
+ return [];
19479
+ }
19480
+ const accepted = [];
19481
+ for (const part of acceptHeader.split(",")) {
19482
+ const [type, ...params] = part.split(";").map((v) => v.trim());
19483
+ let quality = 1;
19484
+ let parameterCount = 0;
19485
+ for (const param of params) {
19486
+ const [key, value] = param.split("=").map((v) => v.trim());
19487
+ if (key === "q") {
19488
+ quality = Number(value);
19489
+ } else {
19490
+ parameterCount++;
19491
+ }
19492
+ }
19493
+ if (quality === 0) {
19494
+ continue;
19495
+ }
19496
+ const [mediaType, mediaSubtype] = type.split("/");
19497
+ const specificity = mediaType === "*" ? 0 : mediaSubtype === "*" ? 1 : 2;
19498
+ accepted.push({ type, quality, specificity, parameterCount });
19499
+ }
19500
+ if (!accepted.length) {
19501
+ return [];
19502
+ }
19503
+ return accepted.sort((left, right) => {
19504
+ if (right.quality !== left.quality) {
19505
+ return right.quality - left.quality;
19506
+ }
19507
+ if (right.specificity !== left.specificity) {
19508
+ return right.specificity - left.specificity;
19509
+ }
19510
+ return right.parameterCount - left.parameterCount;
19511
+ }).map((entry) => entry.type);
19512
+ }
19513
+
19287
19514
  // src/core/handlers/GraphQLHandler.ts
19288
19515
  function isDocumentNode(value) {
19289
19516
  if (value == null) {
@@ -19408,6 +19635,32 @@ Consider naming this operation or using "graphql.operation()" request handler to
19408
19635
  });
19409
19636
  return args.parsedResult.match.matches && hasMatchingOperationType && hasMatchingOperationName;
19410
19637
  }
19638
+ async run(args) {
19639
+ const result = await super.run(args);
19640
+ if (result?.response == null) {
19641
+ return result;
19642
+ }
19643
+ if (!(kDefaultContentType in result.response)) {
19644
+ return result;
19645
+ }
19646
+ const acceptedMimeTypes = getAllAcceptedMimeTypes(
19647
+ args.request.headers.get("accept")
19648
+ );
19649
+ if (acceptedMimeTypes.length === 0) {
19650
+ return result;
19651
+ }
19652
+ const graphqlResponseIndex = acceptedMimeTypes.indexOf(
19653
+ "application/graphql-response+json"
19654
+ );
19655
+ const jsonIndex = acceptedMimeTypes.indexOf("application/json");
19656
+ if (graphqlResponseIndex !== -1 && (jsonIndex === -1 || graphqlResponseIndex <= jsonIndex)) {
19657
+ result.response.headers.set(
19658
+ "content-type",
19659
+ "application/graphql-response+json"
19660
+ );
19661
+ }
19662
+ return result;
19663
+ }
19411
19664
  async matchOperationName(args) {
19412
19665
  if (typeof this.info.operationName === "function") {
19413
19666
  const customPredicateResult = await this.info.operationName({
@@ -19698,7 +19951,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
19698
19951
  promise.resolve(request.result);
19699
19952
  };
19700
19953
  request.onerror = () => {
19701
- console.log(request.error);
19954
+ console.error(request.error);
19702
19955
  promise.reject(
19703
19956
  new Error(
19704
19957
  `Failed to get all WebSocket clients. There is likely an additional output above.`
@@ -20373,7 +20626,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
20373
20626
  frames.push(`id:${message4.id}`);
20374
20627
  }
20375
20628
  if (message4.event) {
20376
- frames.push(`event:${message4.event?.toString()}`);
20629
+ frames.push(`event:${message4.event.toString()}`);
20377
20630
  }
20378
20631
  if (message4.data != null) {
20379
20632
  for (const line of message4.data.toString().split(/\r\n|\r|\n/)) {
@@ -20882,47 +21135,6 @@ Read more: https://mswjs.io/docs/http/intercepting-requests`;
20882
21135
  }
20883
21136
  }
20884
21137
 
20885
- // src/core/utils/HttpResponse/decorators.ts
20886
- var { message: message3 } = statuses_default;
20887
- var kSetCookie = Symbol("kSetCookie");
20888
- function normalizeResponseInit(init = {}) {
20889
- const status = init?.status || 200;
20890
- const statusText = init?.statusText || message3[status] || "";
20891
- const headers = new Headers(init?.headers);
20892
- return {
20893
- ...init,
20894
- headers,
20895
- status,
20896
- statusText
20897
- };
20898
- }
20899
- function decorateResponse(response, init) {
20900
- if (init.type) {
20901
- Object.defineProperty(response, "type", {
20902
- value: init.type,
20903
- enumerable: true,
20904
- writable: false
20905
- });
20906
- }
20907
- const responseCookies = init.headers.get("set-cookie");
20908
- if (responseCookies) {
20909
- Object.defineProperty(response, kSetCookie, {
20910
- value: responseCookies,
20911
- enumerable: false,
20912
- writable: false
20913
- });
20914
- if (typeof document !== "undefined") {
20915
- const responseCookiePairs = Headers2.prototype.getSetCookie.call(
20916
- init.headers
20917
- );
20918
- for (const cookieString of responseCookiePairs) {
20919
- document.cookie = cookieString;
20920
- }
20921
- }
20922
- }
20923
- return response;
20924
- }
20925
-
20926
21138
  // src/core/utils/request/storeResponseCookies.ts
20927
21139
  async function storeResponseCookies(request, response) {
20928
21140
  const responseCookies = Reflect.get(response, kSetCookie);
@@ -20992,115 +21204,6 @@ Read more: https://mswjs.io/docs/http/intercepting-requests`;
20992
21204
  return result?.response;
20993
21205
  };
20994
21206
 
20995
- // src/core/HttpResponse.ts
20996
- var bodyType = Symbol("bodyType");
20997
- var HttpResponse = class _HttpResponse extends FetchResponse {
20998
- [bodyType] = null;
20999
- constructor(body, init) {
21000
- const responseInit = normalizeResponseInit(init);
21001
- super(body, responseInit);
21002
- decorateResponse(this, responseInit);
21003
- }
21004
- static error() {
21005
- return super.error();
21006
- }
21007
- /**
21008
- * Create a `Response` with a `Content-Type: "text/plain"` body.
21009
- * @example
21010
- * HttpResponse.text('hello world')
21011
- * HttpResponse.text('Error', { status: 500 })
21012
- */
21013
- static text(body, init) {
21014
- const responseInit = normalizeResponseInit(init);
21015
- if (!responseInit.headers.has("Content-Type")) {
21016
- responseInit.headers.set("Content-Type", "text/plain");
21017
- }
21018
- if (!responseInit.headers.has("Content-Length")) {
21019
- responseInit.headers.set(
21020
- "Content-Length",
21021
- body ? new Blob([body]).size.toString() : "0"
21022
- );
21023
- }
21024
- return new _HttpResponse(body, responseInit);
21025
- }
21026
- /**
21027
- * Create a `Response` with a `Content-Type: "application/json"` body.
21028
- * @example
21029
- * HttpResponse.json({ firstName: 'John' })
21030
- * HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })
21031
- */
21032
- static json(body, init) {
21033
- const responseInit = normalizeResponseInit(init);
21034
- if (!responseInit.headers.has("Content-Type")) {
21035
- responseInit.headers.set("Content-Type", "application/json");
21036
- }
21037
- const responseText = JSON.stringify(body);
21038
- if (!responseInit.headers.has("Content-Length")) {
21039
- responseInit.headers.set(
21040
- "Content-Length",
21041
- responseText ? new Blob([responseText]).size.toString() : "0"
21042
- );
21043
- }
21044
- return new _HttpResponse(responseText, responseInit);
21045
- }
21046
- /**
21047
- * Create a `Response` with a `Content-Type: "application/xml"` body.
21048
- * @example
21049
- * HttpResponse.xml(`<user name="John" />`)
21050
- * HttpResponse.xml(`<article id="abc-123" />`, { status: 201 })
21051
- */
21052
- static xml(body, init) {
21053
- const responseInit = normalizeResponseInit(init);
21054
- if (!responseInit.headers.has("Content-Type")) {
21055
- responseInit.headers.set("Content-Type", "text/xml");
21056
- }
21057
- return new _HttpResponse(body, responseInit);
21058
- }
21059
- /**
21060
- * Create a `Response` with a `Content-Type: "text/html"` body.
21061
- * @example
21062
- * HttpResponse.html(`<p class="author">Jane Doe</p>`)
21063
- * HttpResponse.html(`<main id="abc-123">Main text</main>`, { status: 201 })
21064
- */
21065
- static html(body, init) {
21066
- const responseInit = normalizeResponseInit(init);
21067
- if (!responseInit.headers.has("Content-Type")) {
21068
- responseInit.headers.set("Content-Type", "text/html");
21069
- }
21070
- return new _HttpResponse(body, responseInit);
21071
- }
21072
- /**
21073
- * Create a `Response` with an `ArrayBuffer` body.
21074
- * @example
21075
- * const buffer = new ArrayBuffer(3)
21076
- * const view = new Uint8Array(buffer)
21077
- * view.set([1, 2, 3])
21078
- *
21079
- * HttpResponse.arrayBuffer(buffer)
21080
- */
21081
- static arrayBuffer(body, init) {
21082
- const responseInit = normalizeResponseInit(init);
21083
- if (!responseInit.headers.has("Content-Type")) {
21084
- responseInit.headers.set("Content-Type", "application/octet-stream");
21085
- }
21086
- if (body && !responseInit.headers.has("Content-Length")) {
21087
- responseInit.headers.set("Content-Length", body.byteLength.toString());
21088
- }
21089
- return new _HttpResponse(body, responseInit);
21090
- }
21091
- /**
21092
- * Create a `Response` with a `FormData` body.
21093
- * @example
21094
- * const data = new FormData()
21095
- * data.set('name', 'Alice')
21096
- *
21097
- * HttpResponse.formData(data)
21098
- */
21099
- static formData(body, init) {
21100
- return new _HttpResponse(body, normalizeResponseInit(init));
21101
- }
21102
- };
21103
-
21104
21207
  // src/core/bypass.ts
21105
21208
  function bypass(input, init) {
21106
21209
  const request = new Request(