(headers: StandardHeaders, body: unknown, buffer: Uint8Array | undefined)
| 352 | } |
| 353 | |
| 354 | async function deserializeBody(headers: StandardHeaders, body: unknown, buffer: Uint8Array | undefined): Promise<StandardBody> { |
| 355 | const contentType = flattenHeader(headers['content-type']) |
| 356 | const contentDisposition = flattenHeader(headers['content-disposition']) |
| 357 | |
| 358 | if (typeof contentDisposition === 'string') { |
| 359 | const filename = getFilenameFromContentDisposition(contentDisposition) ?? 'blob' |
| 360 | return new File(buffer === undefined ? [] : [buffer], filename, { type: contentType }) |
| 361 | } |
| 362 | |
| 363 | if (contentType?.startsWith('multipart/form-data')) { |
| 364 | const tempRes = new Response(buffer, { headers: { 'content-type': contentType } }) |
| 365 | return tempRes.formData() |
| 366 | } |
| 367 | |
| 368 | if (contentType?.startsWith('application/x-www-form-urlencoded') && typeof body === 'string') { |
| 369 | return new URLSearchParams(body) |
| 370 | } |
| 371 | |
| 372 | return body |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * A 16-byte sentinel of 0xFF values guaranteed never to collide with UTF-8 JSON text, |
no test coverage detected