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

19 lines
483 B
TypeScript
Raw Normal View History

export type BodyData = Record<string, string | File>
export async function parseBody(r: Request | Response) {
let body: BodyData = {}
const contentType = r.headers.get('Content-Type')
if (
contentType &&
(contentType.startsWith('multipart/form-data') ||
contentType === 'application/x-www-form-urlencoded')
) {
const form: BodyData = {}
;(await r.formData()).forEach((value, key) => {
form[key] = value
})
body = form
2022-07-02 08:09:45 +02:00
}
return body
2022-07-02 08:09:45 +02:00
}