@mswjs/interceptors 0.23.0 → 0.24.0

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 (51) hide show
  1. package/README.md +1 -1
  2. package/lib/browser/{chunk-3GCTA2IC.js → chunk-2TENISKM.js} +5 -5
  3. package/lib/{node/chunk-IHW3ERPT.js → browser/chunk-3LFH2WCF.js} +1 -9
  4. package/lib/{node/chunk-MPFSBY4S.js → browser/chunk-4CFMDU7Z.js} +36 -9
  5. package/lib/{node/chunk-LTX5IGCQ.mjs → browser/chunk-7II4SWKS.mjs} +0 -8
  6. package/lib/browser/{chunk-DWXGORCS.mjs → chunk-B74BGPYH.mjs} +58 -11
  7. package/lib/browser/{chunk-MW6NCDWE.mjs → chunk-GXJLJMOT.mjs} +33 -7
  8. package/lib/browser/{chunk-AKTXHQ7X.mjs → chunk-LHYX2GOM.mjs} +1 -1
  9. package/lib/browser/{chunk-OBNZMCHS.js → chunk-UGP4JOAM.js} +65 -18
  10. package/lib/browser/index.d.ts +2 -2
  11. package/lib/browser/index.js +4 -4
  12. package/lib/browser/index.mjs +2 -2
  13. package/lib/browser/interceptors/XMLHttpRequest/index.js +4 -4
  14. package/lib/browser/interceptors/XMLHttpRequest/index.mjs +3 -3
  15. package/lib/browser/interceptors/fetch/index.js +3 -3
  16. package/lib/browser/interceptors/fetch/index.mjs +2 -2
  17. package/lib/browser/presets/browser.js +6 -6
  18. package/lib/browser/presets/browser.mjs +4 -4
  19. package/lib/node/RemoteHttpInterceptor.d.ts +2 -3
  20. package/lib/node/RemoteHttpInterceptor.js +15 -16
  21. package/lib/node/RemoteHttpInterceptor.mjs +9 -10
  22. package/lib/node/chunk-3LFH2WCF.js +21 -0
  23. package/lib/node/chunk-7II4SWKS.mjs +21 -0
  24. package/lib/node/{chunk-VJDB3MIV.js → chunk-MVPEJK4V.js} +2 -2
  25. package/lib/node/{chunk-4YIZAGXJ.js → chunk-OOSIWXHX.js} +41 -8
  26. package/lib/node/{chunk-4LRRTLLD.mjs → chunk-PSIO3L7D.mjs} +39 -6
  27. package/lib/node/{chunk-Y5QA6OEZ.mjs → chunk-RGYCLCLK.mjs} +33 -10
  28. package/lib/node/{chunk-CO6XRA5H.mjs → chunk-UWSK5F3S.mjs} +58 -11
  29. package/lib/node/{chunk-NUSH7ACE.mjs → chunk-VS3GJPUE.mjs} +1 -1
  30. package/lib/{browser/chunk-7VJMJSIJ.js → node/chunk-XYZRP5S2.js} +35 -13
  31. package/lib/node/{chunk-GLYFVYMU.js → chunk-YCEMBJEM.js} +62 -15
  32. package/lib/node/index.js +4 -4
  33. package/lib/node/index.mjs +3 -3
  34. package/lib/node/interceptors/ClientRequest/index.js +3 -3
  35. package/lib/node/interceptors/ClientRequest/index.mjs +2 -2
  36. package/lib/node/interceptors/XMLHttpRequest/index.js +4 -4
  37. package/lib/node/interceptors/XMLHttpRequest/index.mjs +3 -3
  38. package/lib/node/interceptors/fetch/index.js +2 -2
  39. package/lib/node/interceptors/fetch/index.mjs +1 -1
  40. package/lib/node/presets/node.js +6 -6
  41. package/lib/node/presets/node.mjs +4 -4
  42. package/package.json +15 -18
  43. package/src/RemoteHttpInterceptor.ts +6 -7
  44. package/src/interceptors/ClientRequest/utils/createRequest.ts +0 -1
  45. package/src/interceptors/ClientRequest/utils/createResponse.ts +34 -3
  46. package/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts +15 -7
  47. package/src/interceptors/XMLHttpRequest/utils/createResponse.ts +27 -5
  48. package/src/utils/bufferUtils.ts +0 -2
  49. package/lib/browser/chunk-MQA5WAD4.mjs +0 -2139
  50. package/lib/browser/chunk-QAZ3SPQZ.js +0 -2139
  51. package/src/shims/webEncoding.ts +0 -9
@@ -1,12 +1,34 @@
1
- import { stringToHeaders } from 'headers-polyfill'
2
-
1
+ /**
2
+ * Creates a Fetch API `Response` instance from the given
3
+ * `XMLHttpRequest` instance and a response body.
4
+ */
3
5
  export function createResponse(
4
6
  request: XMLHttpRequest,
5
- responseBody: BodyInit | null
7
+ body: BodyInit | null
6
8
  ): Response {
7
- return new Response(responseBody, {
9
+ return new Response(body, {
8
10
  status: request.status,
9
11
  statusText: request.statusText,
10
- headers: stringToHeaders(request.getAllResponseHeaders()),
12
+ headers: createHeadersFromXMLHttpReqestHeaders(
13
+ request.getAllResponseHeaders()
14
+ ),
11
15
  })
12
16
  }
17
+
18
+ function createHeadersFromXMLHttpReqestHeaders(headersString: string): Headers {
19
+ const headers = new Headers()
20
+
21
+ const lines = headersString.split(/[\r\n]+/)
22
+ for (const line of lines) {
23
+ if (line.trim() === '') {
24
+ continue
25
+ }
26
+
27
+ const [name, ...parts] = line.split(': ')
28
+ const value = parts.join(': ')
29
+
30
+ headers.append(name, value)
31
+ }
32
+
33
+ return headers
34
+ }
@@ -1,5 +1,3 @@
1
- import { TextEncoder, TextDecoder } from '../shims/webEncoding'
2
-
3
1
  const encoder = new TextEncoder()
4
2
 
5
3
  export function encodeBuffer(text: string): Uint8Array {