| 11 | } |
| 12 | |
| 13 | const 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 | |
| 36 | const worker = setupWorker( |
| 37 | http.get('/resource', forwardRequestBody), |