@zimic/interceptor 1.2.7-canary.2 → 1.3.0-canary.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.
Files changed (37) hide show
  1. package/dist/{chunk-6GEP6R3L.mjs → chunk-4L2JH2L4.mjs} +80 -23
  2. package/dist/chunk-4L2JH2L4.mjs.map +1 -0
  3. package/dist/{chunk-PB4TJVK3.js → chunk-F5OGZSHS.js} +80 -23
  4. package/dist/chunk-F5OGZSHS.js.map +1 -0
  5. package/dist/cli.js +17 -19
  6. package/dist/cli.js.map +1 -1
  7. package/dist/cli.mjs +2 -4
  8. package/dist/cli.mjs.map +1 -1
  9. package/dist/http.d.ts +95 -6
  10. package/dist/http.js +253 -186
  11. package/dist/http.js.map +1 -1
  12. package/dist/http.mjs +254 -187
  13. package/dist/http.mjs.map +1 -1
  14. package/dist/server.js +6 -6
  15. package/dist/server.mjs +1 -1
  16. package/package.json +2 -2
  17. package/src/cli/server/start.ts +7 -2
  18. package/src/http/interceptor/HttpInterceptorClient.ts +8 -10
  19. package/src/http/interceptor/types/options.ts +11 -5
  20. package/src/http/interceptorWorker/HttpInterceptorWorker.ts +73 -15
  21. package/src/http/interceptorWorker/LocalHttpInterceptorWorker.ts +36 -11
  22. package/src/http/interceptorWorker/RemoteHttpInterceptorWorker.ts +34 -13
  23. package/src/http/interceptorWorker/types/http.ts +6 -1
  24. package/src/http/interceptorWorker/types/msw.ts +0 -9
  25. package/src/http/requestHandler/HttpRequestHandlerClient.ts +2 -4
  26. package/src/http/requestHandler/errors/TimesCheckError.ts +1 -1
  27. package/src/http/requestHandler/types/requests.ts +16 -2
  28. package/src/server/InterceptorServer.ts +13 -5
  29. package/src/server/constants.ts +1 -1
  30. package/src/server/errors/UnsupportedResponseBypassError.ts +11 -0
  31. package/src/utils/crypto.ts +1 -1
  32. package/src/utils/fetch.ts +25 -6
  33. package/src/utils/files.ts +1 -1
  34. package/src/utils/logging.ts +2 -2
  35. package/src/webSocket/WebSocketClient.ts +1 -1
  36. package/dist/chunk-6GEP6R3L.mjs.map +0 -1
  37. package/dist/chunk-PB4TJVK3.js.map +0 -1
package/dist/http.js CHANGED
@@ -123,19 +123,144 @@ var DisabledRequestSavingError = class extends TypeError {
123
123
  };
124
124
  var DisabledRequestSavingError_default = DisabledRequestSavingError;
125
125
 
126
- // ../zimic-utils/dist/chunk-5UH44FTS.mjs
126
+ // ../zimic-utils/dist/data.mjs
127
127
  function isDefined(value) {
128
128
  return value !== void 0 && value !== null;
129
129
  }
130
130
  var isDefined_default = isDefined;
131
-
132
- // ../zimic-utils/dist/data/isNonEmpty.mjs
133
131
  function isNonEmpty(value) {
134
132
  return isDefined_default(value) && value !== "";
135
133
  }
136
134
  var isNonEmpty_default = isNonEmpty;
135
+ async function blobEquals(blob, otherBlob) {
136
+ if (blob.type !== otherBlob.type || blob.size !== otherBlob.size) {
137
+ return false;
138
+ }
139
+ const reader = blob.stream().getReader();
140
+ const otherReader = otherBlob.stream().getReader();
141
+ let buffer = new Uint8Array(0);
142
+ let otherBuffer = new Uint8Array(0);
143
+ try {
144
+ while (true) {
145
+ const bufferReadPromises = [];
146
+ if (buffer.length === 0) {
147
+ bufferReadPromises.push(
148
+ reader.read().then((result) => {
149
+ if (!result.done) {
150
+ buffer = result.value;
151
+ }
152
+ })
153
+ );
154
+ }
155
+ if (otherBuffer.length === 0) {
156
+ bufferReadPromises.push(
157
+ otherReader.read().then((result) => {
158
+ if (!result.done) {
159
+ otherBuffer = result.value;
160
+ }
161
+ })
162
+ );
163
+ }
164
+ await Promise.all(bufferReadPromises);
165
+ const haveStreamsEndedTogether = buffer.length === 0 && otherBuffer.length === 0;
166
+ if (haveStreamsEndedTogether) {
167
+ return true;
168
+ }
169
+ const hasOneStreamEndedBeforeTheOther = buffer.length === 0 && otherBuffer.length > 0 || buffer.length > 0 && otherBuffer.length === 0;
170
+ if (hasOneStreamEndedBeforeTheOther) {
171
+ return false;
172
+ }
173
+ const minimumByteLength = Math.min(buffer.length, otherBuffer.length);
174
+ for (let byteIndex = 0; byteIndex < minimumByteLength; byteIndex++) {
175
+ if (buffer[byteIndex] !== otherBuffer[byteIndex]) {
176
+ return false;
177
+ }
178
+ }
179
+ buffer = buffer.slice(minimumByteLength);
180
+ otherBuffer = otherBuffer.slice(minimumByteLength);
181
+ }
182
+ } finally {
183
+ reader.releaseLock();
184
+ otherReader.releaseLock();
185
+ }
186
+ }
187
+ var blobEquals_default = blobEquals;
188
+ function isPrimitiveJSONValue(value) {
189
+ return typeof value !== "object" || value === null;
190
+ }
191
+ function jsonContains(value, otherValue) {
192
+ if (isPrimitiveJSONValue(value)) {
193
+ return value === otherValue;
194
+ }
195
+ if (isPrimitiveJSONValue(otherValue)) {
196
+ return false;
197
+ }
198
+ if (Array.isArray(value)) {
199
+ if (!Array.isArray(otherValue)) {
200
+ return false;
201
+ }
202
+ if (value.length < otherValue.length) {
203
+ return false;
204
+ }
205
+ let lastMatchedIndex = -1;
206
+ return otherValue.every((otherItem) => {
207
+ for (let index = lastMatchedIndex + 1; index < value.length; index++) {
208
+ if (jsonContains(value[index], otherItem)) {
209
+ lastMatchedIndex = index;
210
+ return true;
211
+ }
212
+ }
213
+ return false;
214
+ });
215
+ }
216
+ if (Array.isArray(otherValue)) {
217
+ return false;
218
+ }
219
+ const valueKeys = Object.keys(value);
220
+ const otherValueKeys = Object.keys(otherValue);
221
+ if (valueKeys.length < otherValueKeys.length) {
222
+ return false;
223
+ }
224
+ return otherValueKeys.every((key) => {
225
+ const subValue = value[key];
226
+ const subOtherValue = otherValue[key];
227
+ return jsonContains(subValue, subOtherValue);
228
+ });
229
+ }
230
+ var jsonContains_default = jsonContains;
231
+ function jsonEquals(value, otherValue) {
232
+ if (isPrimitiveJSONValue(value)) {
233
+ return value === otherValue;
234
+ }
235
+ if (isPrimitiveJSONValue(otherValue)) {
236
+ return false;
237
+ }
238
+ if (Array.isArray(value)) {
239
+ if (!Array.isArray(otherValue)) {
240
+ return false;
241
+ }
242
+ if (value.length !== otherValue.length) {
243
+ return false;
244
+ }
245
+ return value.every((item, index) => jsonEquals(item, otherValue[index]));
246
+ }
247
+ if (Array.isArray(otherValue)) {
248
+ return false;
249
+ }
250
+ const valueKeys = Object.keys(value);
251
+ const otherValueKeys = Object.keys(otherValue);
252
+ if (valueKeys.length !== otherValueKeys.length) {
253
+ return false;
254
+ }
255
+ return valueKeys.every((key) => {
256
+ const subValue = value[key];
257
+ const subOtherValue = otherValue[key];
258
+ return jsonEquals(subValue, subOtherValue);
259
+ });
260
+ }
261
+ var jsonEquals_default = jsonEquals;
137
262
 
138
- // ../zimic-utils/dist/import/createCachedDynamicImport.mjs
263
+ // ../zimic-utils/dist/chunk-W66SQPEM.mjs
139
264
  function createCachedDynamicImport(importModuleDynamically) {
140
265
  let cachedImportResult;
141
266
  return async function importModuleDynamicallyWithCache() {
@@ -145,7 +270,7 @@ function createCachedDynamicImport(importModuleDynamically) {
145
270
  }
146
271
  var createCachedDynamicImport_default = createCachedDynamicImport;
147
272
 
148
- // ../zimic-utils/dist/logging/Logger.mjs
273
+ // ../zimic-utils/dist/logging.mjs
149
274
  var Logger = class _Logger {
150
275
  prefix;
151
276
  raw;
@@ -375,142 +500,7 @@ var TimesCheckError = class extends TypeError {
375
500
  };
376
501
  var TimesCheckError_default = TimesCheckError;
377
502
 
378
- // ../zimic-utils/dist/chunk-BSG74SVQ.mjs
379
- async function blobEquals(blob, otherBlob) {
380
- if (blob.type !== otherBlob.type || blob.size !== otherBlob.size) {
381
- return false;
382
- }
383
- const reader = blob.stream().getReader();
384
- const otherReader = otherBlob.stream().getReader();
385
- let buffer = new Uint8Array(0);
386
- let otherBuffer = new Uint8Array(0);
387
- try {
388
- while (true) {
389
- const bufferReadPromises = [];
390
- if (buffer.length === 0) {
391
- bufferReadPromises.push(
392
- reader.read().then((result) => {
393
- if (!result.done) {
394
- buffer = result.value;
395
- }
396
- })
397
- );
398
- }
399
- if (otherBuffer.length === 0) {
400
- bufferReadPromises.push(
401
- otherReader.read().then((result) => {
402
- if (!result.done) {
403
- otherBuffer = result.value;
404
- }
405
- })
406
- );
407
- }
408
- await Promise.all(bufferReadPromises);
409
- const haveStreamsEndedTogether = buffer.length === 0 && otherBuffer.length === 0;
410
- if (haveStreamsEndedTogether) {
411
- return true;
412
- }
413
- const hasOneStreamEndedBeforeTheOther = buffer.length === 0 && otherBuffer.length > 0 || buffer.length > 0 && otherBuffer.length === 0;
414
- if (hasOneStreamEndedBeforeTheOther) {
415
- return false;
416
- }
417
- const minimumByteLength = Math.min(buffer.length, otherBuffer.length);
418
- for (let byteIndex = 0; byteIndex < minimumByteLength; byteIndex++) {
419
- if (buffer[byteIndex] !== otherBuffer[byteIndex]) {
420
- return false;
421
- }
422
- }
423
- buffer = buffer.slice(minimumByteLength);
424
- otherBuffer = otherBuffer.slice(minimumByteLength);
425
- }
426
- } finally {
427
- reader.releaseLock();
428
- otherReader.releaseLock();
429
- }
430
- }
431
- var blobEquals_default = blobEquals;
432
-
433
- // ../zimic-utils/dist/chunk-LBZAJMTR.mjs
434
- function isPrimitiveJSONValue(value) {
435
- return typeof value !== "object" || value === null;
436
- }
437
-
438
- // ../zimic-utils/dist/data/jsonContains.mjs
439
- function jsonContains(value, otherValue) {
440
- if (isPrimitiveJSONValue(value)) {
441
- return value === otherValue;
442
- }
443
- if (isPrimitiveJSONValue(otherValue)) {
444
- return false;
445
- }
446
- if (Array.isArray(value)) {
447
- if (!Array.isArray(otherValue)) {
448
- return false;
449
- }
450
- if (value.length < otherValue.length) {
451
- return false;
452
- }
453
- let lastMatchedIndex = -1;
454
- return otherValue.every((otherItem) => {
455
- for (let index = lastMatchedIndex + 1; index < value.length; index++) {
456
- if (jsonContains(value[index], otherItem)) {
457
- lastMatchedIndex = index;
458
- return true;
459
- }
460
- }
461
- return false;
462
- });
463
- }
464
- if (Array.isArray(otherValue)) {
465
- return false;
466
- }
467
- const valueKeys = Object.keys(value);
468
- const otherValueKeys = Object.keys(otherValue);
469
- if (valueKeys.length < otherValueKeys.length) {
470
- return false;
471
- }
472
- return otherValueKeys.every((key) => {
473
- const subValue = value[key];
474
- const subOtherValue = otherValue[key];
475
- return jsonContains(subValue, subOtherValue);
476
- });
477
- }
478
- var jsonContains_default = jsonContains;
479
-
480
- // ../zimic-utils/dist/data/jsonEquals.mjs
481
- function jsonEquals(value, otherValue) {
482
- if (isPrimitiveJSONValue(value)) {
483
- return value === otherValue;
484
- }
485
- if (isPrimitiveJSONValue(otherValue)) {
486
- return false;
487
- }
488
- if (Array.isArray(value)) {
489
- if (!Array.isArray(otherValue)) {
490
- return false;
491
- }
492
- if (value.length !== otherValue.length) {
493
- return false;
494
- }
495
- return value.every((item, index) => jsonEquals(item, otherValue[index]));
496
- }
497
- if (Array.isArray(otherValue)) {
498
- return false;
499
- }
500
- const valueKeys = Object.keys(value);
501
- const otherValueKeys = Object.keys(otherValue);
502
- if (valueKeys.length !== otherValueKeys.length) {
503
- return false;
504
- }
505
- return valueKeys.every((key) => {
506
- const subValue = value[key];
507
- const subOtherValue = otherValue[key];
508
- return jsonEquals(subValue, subOtherValue);
509
- });
510
- }
511
- var jsonEquals_default = jsonEquals;
512
-
513
- // ../zimic-utils/dist/chunk-QISSVK3C.mjs
503
+ // ../zimic-utils/dist/time.mjs
514
504
  function waitForDelay(milliseconds) {
515
505
  return new Promise((resolve) => {
516
506
  setTimeout(resolve, milliseconds);
@@ -914,7 +904,7 @@ var LocalHttpRequestHandler = class {
914
904
  };
915
905
  var LocalHttpRequestHandler_default = LocalHttpRequestHandler;
916
906
 
917
- // ../zimic-utils/dist/chunk-VPHA4ZCK.mjs
907
+ // ../zimic-utils/dist/url.mjs
918
908
  function createPathCharactersToEscapeRegex() {
919
909
  return /([.(){}+$])/g;
920
910
  }
@@ -985,8 +975,6 @@ function createRegexFromPath(path) {
985
975
  return new RegExp(`^/?${pathRegexContent}/?$`);
986
976
  }
987
977
  var createRegexFromPath_default = createRegexFromPath;
988
-
989
- // ../zimic-utils/dist/url/excludeNonPathParams.mjs
990
978
  function excludeNonPathParams(url) {
991
979
  url.hash = "";
992
980
  url.search = "";
@@ -995,8 +983,29 @@ function excludeNonPathParams(url) {
995
983
  return url;
996
984
  }
997
985
  var excludeNonPathParams_default = excludeNonPathParams;
998
-
999
- // ../zimic-utils/dist/url/validateURLProtocol.mjs
986
+ var DuplicatedPathParamError = class extends Error {
987
+ constructor(path, paramName) {
988
+ super(
989
+ `The path parameter '${paramName}' appears more than once in '${path}'. This is not supported. Please make sure that each parameter is unique.`
990
+ );
991
+ this.name = "DuplicatedPathParamError";
992
+ }
993
+ };
994
+ function validatePathParams(path) {
995
+ const pathParamMatches = path.toString().matchAll(createPathParamRegex());
996
+ const uniqueParamNames = /* @__PURE__ */ new Set();
997
+ for (const paramMatch of pathParamMatches) {
998
+ const paramName = paramMatch.groups?.identifier;
999
+ if (!paramName) {
1000
+ continue;
1001
+ }
1002
+ if (uniqueParamNames.has(paramName)) {
1003
+ throw new DuplicatedPathParamError(path, paramName);
1004
+ }
1005
+ uniqueParamNames.add(paramName);
1006
+ }
1007
+ }
1008
+ var validatePathParams_default = validatePathParams;
1000
1009
  var UnsupportedURLProtocolError = class extends TypeError {
1001
1010
  constructor(protocol, availableProtocols) {
1002
1011
  super(
@@ -1069,6 +1078,7 @@ var DEFAULT_UNHANDLED_REQUEST_STRATEGY = Object.freeze({
1069
1078
  });
1070
1079
 
1071
1080
  // src/http/interceptorWorker/HttpInterceptorWorker.ts
1081
+ var RESPONSE_ACTION_SYMBOL = Symbol.for("HttpResponse.action");
1072
1082
  var HttpInterceptorWorker = class _HttpInterceptorWorker {
1073
1083
  platform = null;
1074
1084
  isRunning = false;
@@ -1165,17 +1175,57 @@ var HttpInterceptorWorker = class _HttpInterceptorWorker {
1165
1175
  }
1166
1176
  return interceptor.onUnhandledRequest;
1167
1177
  }
1168
- static createResponseFromDeclaration(request, declaration) {
1178
+ static setResponseAction(response, action) {
1179
+ Object.defineProperty(response, RESPONSE_ACTION_SYMBOL, {
1180
+ value: action,
1181
+ enumerable: false,
1182
+ configurable: false,
1183
+ writable: false
1184
+ });
1185
+ }
1186
+ static getResponseAction(response) {
1187
+ if (!(RESPONSE_ACTION_SYMBOL in response)) {
1188
+ return void 0;
1189
+ }
1190
+ const action = response[RESPONSE_ACTION_SYMBOL];
1191
+ if (action !== "bypass" && action !== "reject") {
1192
+ return void 0;
1193
+ }
1194
+ return action;
1195
+ }
1196
+ createBypassedResponse() {
1197
+ const response = Response.redirect("about:blank", 302);
1198
+ _HttpInterceptorWorker.setResponseAction(response, "bypass");
1199
+ return response;
1200
+ }
1201
+ static isBypassedResponse(response) {
1202
+ return this.getResponseAction(response) === "bypass";
1203
+ }
1204
+ createRejectedResponse() {
1205
+ const response = Response.error();
1206
+ _HttpInterceptorWorker.setResponseAction(response, "reject");
1207
+ return response;
1208
+ }
1209
+ static isRejectedResponse(response) {
1210
+ return this.getResponseAction(response) === "reject";
1211
+ }
1212
+ createResponseFromDeclaration(request, declaration) {
1213
+ if ("action" in declaration) {
1214
+ if (declaration.action === "bypass") {
1215
+ return this.createBypassedResponse();
1216
+ } else {
1217
+ return this.createRejectedResponse();
1218
+ }
1219
+ }
1169
1220
  const headers = new http.HttpHeaders(declaration.headers);
1170
- const status = declaration.status;
1171
- const canHaveBody = methodCanHaveResponseBody(request.method) && status !== 204;
1221
+ const canHaveBody = methodCanHaveResponseBody(request.method) && declaration.status !== 204;
1172
1222
  if (!canHaveBody) {
1173
- return new Response(null, { headers, status });
1223
+ return new Response(null, { headers, status: declaration.status });
1174
1224
  }
1175
1225
  if (typeof declaration.body === "string" || declaration.body === null || declaration.body === void 0 || declaration.body instanceof FormData || declaration.body instanceof URLSearchParams || declaration.body instanceof Blob || declaration.body instanceof ArrayBuffer || declaration.body instanceof ReadableStream) {
1176
- return new Response(declaration.body ?? null, { headers, status });
1226
+ return new Response(declaration.body ?? null, { headers, status: declaration.status });
1177
1227
  }
1178
- return Response.json(declaration.body, { headers, status });
1228
+ return Response.json(declaration.body, { headers, status: declaration.status });
1179
1229
  }
1180
1230
  static async parseRawUnhandledRequest(request) {
1181
1231
  return this.parseRawRequest(
@@ -1604,8 +1654,9 @@ var HttpInterceptorClient = class {
1604
1654
  if (!responseDeclaration) {
1605
1655
  return null;
1606
1656
  }
1607
- const response = HttpInterceptorWorker_default.createResponseFromDeclaration(request, responseDeclaration);
1608
- if (this.requestSaving.enabled) {
1657
+ const response = await this.workerOrThrow.createResponseFromDeclaration(request, responseDeclaration);
1658
+ const shouldSaveInterceptedRequest = this.requestSaving.enabled && response && !HttpInterceptorWorker_default.isRejectedResponse(response);
1659
+ if (shouldSaveInterceptedRequest) {
1609
1660
  const responseClone = response.clone();
1610
1661
  const parsedResponse = await HttpInterceptorWorker_default.parseRawResponse(responseClone);
1611
1662
  matchedHandler.saveInterceptedRequest(parsedRequest, parsedResponse);
@@ -1680,31 +1731,6 @@ var HttpInterceptorClient = class {
1680
1731
  }
1681
1732
  };
1682
1733
  var HttpInterceptorClient_default = HttpInterceptorClient;
1683
-
1684
- // ../zimic-utils/dist/url/validatePathParams.mjs
1685
- var DuplicatedPathParamError = class extends Error {
1686
- constructor(path, paramName) {
1687
- super(
1688
- `The path parameter '${paramName}' appears more than once in '${path}'. This is not supported. Please make sure that each parameter is unique.`
1689
- );
1690
- this.name = "DuplicatedPathParamError";
1691
- }
1692
- };
1693
- function validatePathParams(path) {
1694
- const pathParamMatches = path.toString().matchAll(createPathParamRegex());
1695
- const uniqueParamNames = /* @__PURE__ */ new Set();
1696
- for (const paramMatch of pathParamMatches) {
1697
- const paramName = paramMatch.groups?.identifier;
1698
- if (!paramName) {
1699
- continue;
1700
- }
1701
- if (uniqueParamNames.has(paramName)) {
1702
- throw new DuplicatedPathParamError(path, paramName);
1703
- }
1704
- uniqueParamNames.add(paramName);
1705
- }
1706
- }
1707
- var validatePathParams_default = validatePathParams;
1708
1734
  var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1709
1735
  internalWorker;
1710
1736
  httpHandlersByMethod = {
@@ -1822,7 +1848,7 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1822
1848
  const requestClone = request.clone();
1823
1849
  let response = null;
1824
1850
  try {
1825
- response = await createResponse({ ...context, request });
1851
+ response = await createResponse({ request });
1826
1852
  } catch (error) {
1827
1853
  console.error(error);
1828
1854
  }
@@ -1841,6 +1867,23 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1841
1867
  };
1842
1868
  methodHandlers.push(handler);
1843
1869
  }
1870
+ async createResponseFromDeclaration(request, declaration) {
1871
+ const requestClone = request.clone();
1872
+ const response = await super.createResponseFromDeclaration(request, declaration);
1873
+ if (response && HttpInterceptorWorker_default.isBypassedResponse(response)) {
1874
+ try {
1875
+ const response2 = await fetch(msw.bypass(requestClone));
1876
+ return response2;
1877
+ } catch (error) {
1878
+ console.error(error);
1879
+ return null;
1880
+ }
1881
+ }
1882
+ if (response && HttpInterceptorWorker_default.isRejectedResponse(response)) {
1883
+ return response;
1884
+ }
1885
+ return response;
1886
+ }
1844
1887
  async createResponseForRequest(request) {
1845
1888
  const methodHandlers = this.httpHandlersByMethod[request.method];
1846
1889
  const requestURL = excludeNonPathParams_default(new URL(request.url));
@@ -1898,6 +1941,17 @@ var LocalHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
1898
1941
  };
1899
1942
  var LocalHttpInterceptorWorker_default = LocalHttpInterceptorWorker;
1900
1943
 
1944
+ // src/server/errors/UnsupportedResponseBypassError.ts
1945
+ var UnsupportedResponseBypassError = class extends Error {
1946
+ constructor() {
1947
+ super(
1948
+ "Remote interceptors cannot bypass responses. Use `{ action: 'reject' }` instead.\n\nLearn more: https://zimic.dev/docs/interceptor/api/http-request-handler#handlerrespond"
1949
+ );
1950
+ this.name = "UnsupportedResponseBypassError";
1951
+ }
1952
+ };
1953
+ var UnsupportedResponseBypassError_default = UnsupportedResponseBypassError;
1954
+
1901
1955
  // src/utils/crypto.ts
1902
1956
  var importCrypto = createCachedDynamicImport_default(async () => {
1903
1957
  const globalCrypto = globalThis.crypto;
@@ -1925,6 +1979,8 @@ async function serializeResponse(response) {
1925
1979
  const responseClone = response.clone();
1926
1980
  const serializedBody = responseClone.body ? convertArrayBufferToBase64(await responseClone.arrayBuffer()) : null;
1927
1981
  return {
1982
+ type: response.type,
1983
+ action: HttpInterceptorWorker_default.getResponseAction(response),
1928
1984
  status: response.status,
1929
1985
  statusText: response.statusText,
1930
1986
  headers: Object.fromEntries(response.headers),
@@ -2401,8 +2457,8 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2401
2457
  const request = deserializeRequest(serializedRequest);
2402
2458
  try {
2403
2459
  const rawResponse = await handler?.createResponse({ request }) ?? null;
2404
- const response = rawResponse && request.method === "HEAD" ? new Response(null, rawResponse) : rawResponse;
2405
- if (response) {
2460
+ if (rawResponse) {
2461
+ const response = methodCanHaveResponseBody(request.method) ? rawResponse : new Response(null, rawResponse);
2406
2462
  return { response: await serializeResponse(response) };
2407
2463
  }
2408
2464
  } catch (error) {
@@ -2449,10 +2505,7 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2449
2505
  method,
2450
2506
  path,
2451
2507
  interceptor,
2452
- async createResponse(context) {
2453
- const response = await createResponse(context);
2454
- return response;
2455
- }
2508
+ createResponse
2456
2509
  };
2457
2510
  this.httpHandlers.set(handler.id, handler);
2458
2511
  await this.webSocketClient.request("interceptors/workers/commit", {
@@ -2462,6 +2515,16 @@ var RemoteHttpInterceptorWorker = class extends HttpInterceptorWorker_default {
2462
2515
  path: handler.path
2463
2516
  });
2464
2517
  }
2518
+ async createResponseFromDeclaration(request, declaration) {
2519
+ const response = await super.createResponseFromDeclaration(request, declaration);
2520
+ if (response && HttpInterceptorWorker_default.isBypassedResponse(response)) {
2521
+ throw new UnsupportedResponseBypassError_default();
2522
+ }
2523
+ if (response && HttpInterceptorWorker_default.isRejectedResponse(response)) {
2524
+ return response;
2525
+ }
2526
+ return response;
2527
+ }
2465
2528
  async clearHandlers(options = {}) {
2466
2529
  if (!this.isRunning) {
2467
2530
  throw new NotRunningHttpInterceptorError_default();
@@ -2821,6 +2884,10 @@ var InvalidFormDataError = class extends http.InvalidFormDataError {
2821
2884
  };
2822
2885
  var InvalidJSONError = class extends http.InvalidJSONError {
2823
2886
  };
2887
+ /* istanbul ignore else -- @preserve
2888
+ * The else is a fallback for when the error is not an instance of Error. */
2889
+ /* istanbul ignore if -- @preserve
2890
+ * This is just a type guard to ensure the value is valid. In practice, this condition should never be true. */
2824
2891
  /* istanbul ignore next -- @preserve
2825
2892
  * Ignoring because there will always be a handler for the given method and path at this point. */
2826
2893
  /* istanbul ignore if -- @preserve