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.
@@ -192,12 +192,14 @@ async function getResponse(event, client, requestId) {
192
192
  const requestClone = request.clone()
193
193
 
194
194
  function passthrough() {
195
- const headers = Object.fromEntries(requestClone.headers.entries())
196
-
197
- // Remove internal MSW request header so the passthrough request
198
- // complies with any potential CORS preflight checks on the server.
199
- // Some servers forbid unknown request headers.
200
- delete headers['x-msw-intention']
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) {