MCPcopy
hub / github.com/mswjs/msw / forwardMultipartRequestBody

Function forwardMultipartRequestBody

test/browser/rest-api/body.mocks.ts:13–34  ·  view source on GitHub ↗
({
  request,
})

Source from the content-addressed store, hash-verified

11}
12
13const forwardMultipartRequestBody: ResponseResolver<any> = async ({
14 request,
15}) => {
16 const formData = await request.formData()
17 const responseBody: Record<string, string | Array<string>> = {}
18
19 for (const [name, value] of formData.entries()) {
20 const nextValue = value instanceof File ? await value.text() : value
21
22 if (responseBody[name]) {
23 responseBody[name] = Array.prototype.concat(
24 [],
25 responseBody[name],
26 nextValue,
27 )
28 } else {
29 responseBody[name] = nextValue
30 }
31 }
32
33 return HttpResponse.json(responseBody)
34}
35
36const worker = setupWorker(
37 http.get('/resource', forwardRequestBody),

Callers

nothing calls this directly

Calls 3

formDataMethod · 0.80
textMethod · 0.80
jsonMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…