0
0
mirror of https://github.com/honojs/hono.git synced 2024-12-01 10:51:01 +00:00
hono/deno_dist/utils/body.ts

17 lines
529 B
TypeScript
Raw Normal View History

export async function parseBody(r: Request | Response): Promise<Record<string, string | File>> {
let body: Record<string, string | File> = {}
const contentType = r.headers.get('Content-Type')
if (
contentType &&
(contentType.startsWith('multipart/form-data') ||
contentType === 'application/x-www-form-urlencoded')
) {
2022-07-02 06:09:45 +00:00
const form: Record<string, string | File> = {}
body = [...(await r.formData())].reduce((acc, cur) => {
2022-07-02 06:09:45 +00:00
acc[cur[0]] = cur[1]
return acc
}, form)
}
return body
2022-07-02 06:09:45 +00:00
}