msw 2.6.2 → 2.6.4
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/README.md +6 -1
- package/lib/browser/index.js +1 -1
- package/lib/browser/index.mjs +1 -1
- package/lib/core/bypass.js +1 -1
- package/lib/core/bypass.js.map +1 -1
- package/lib/core/bypass.mjs +1 -1
- package/lib/core/bypass.mjs.map +1 -1
- package/lib/core/utils/handleRequest.d.mts +0 -5
- package/lib/core/utils/handleRequest.d.ts +0 -5
- package/lib/core/utils/handleRequest.js +3 -7
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs +3 -7
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/iife/index.js +5 -9
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +10 -8
- package/lib/native/index.js +17 -1
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +17 -1
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.js +17 -1
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +17 -1
- package/lib/node/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/bypass.test.ts +25 -14
- package/src/core/bypass.ts +7 -5
- package/src/core/passthrough.test.ts +1 -3
- package/src/core/utils/handleRequest.test.ts +5 -90
- package/src/core/utils/handleRequest.ts +4 -17
- package/src/mockServiceWorker.js +8 -6
- package/src/node/SetupServerCommonApi.ts +23 -0
package/src/mockServiceWorker.js
CHANGED
|
@@ -192,12 +192,14 @@ async function getResponse(event, client, requestId) {
|
|
|
192
192
|
const requestClone = request.clone()
|
|
193
193
|
|
|
194
194
|
function passthrough() {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
//
|
|
200
|
-
|
|
195
|
+
// Cast the request headers to a new Headers instance
|
|
196
|
+
// so the headers can be manipulated with.
|
|
197
|
+
const headers = new Headers(requestClone.headers)
|
|
198
|
+
|
|
199
|
+
// Remove the "accept" header value that marked this request as passthrough.
|
|
200
|
+
// This prevents request alteration and also keeps it compliant with the
|
|
201
|
+
// user-defined CORS policies.
|
|
202
|
+
headers.delete('accept', 'msw/passthrough')
|
|
201
203
|
|
|
202
204
|
return fetch(requestClone, { headers })
|
|
203
205
|
}
|
|
@@ -67,6 +67,29 @@ export class SetupServerCommonApi
|
|
|
67
67
|
.filter(isHandlerKind('RequestHandler')),
|
|
68
68
|
this.resolvedOptions,
|
|
69
69
|
this.emitter,
|
|
70
|
+
{
|
|
71
|
+
onPassthroughResponse(request) {
|
|
72
|
+
const acceptHeader = request.headers.get('accept')
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @note Remove the internal bypass request header.
|
|
76
|
+
* In the browser, this is done by the worker script.
|
|
77
|
+
* In Node.js, it has to be done here.
|
|
78
|
+
*/
|
|
79
|
+
if (acceptHeader) {
|
|
80
|
+
const nextAcceptHeader = acceptHeader.replace(
|
|
81
|
+
/(,\s+)?msw\/passthrough/,
|
|
82
|
+
'',
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
if (nextAcceptHeader) {
|
|
86
|
+
request.headers.set('accept', nextAcceptHeader)
|
|
87
|
+
} else {
|
|
88
|
+
request.headers.delete('accept')
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
},
|
|
70
93
|
)
|
|
71
94
|
|
|
72
95
|
if (response) {
|