Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function readRequestBody(request) {
- const { headers } = request
- const contentType = headers.get('content-type')
- if (contentType.includes('application/json')) {
- const body = await request.json()
- return JSON.stringify(body)
- } else if (contentType.includes('application/text')) {
- const body = await request.text()
- return body
- } else if (contentType.includes('text/html')) {
- const body = await request.text()
- return body
- } else if (contentType.includes('form')) {
- const formData = await request.formData()
- let body = {}
- for (let entry of formData.entries()) {
- body[entry[0]] = entry[1]
- }
- return JSON.stringify(body)
- } else {
- let myBlob = await request.blob()
- var objectURL = URL.createObjectURL(myBlob)
- return objectURL
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement