Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. async function readRequestBody(request) {
  2. const { headers } = request
  3. const contentType = headers.get('content-type')
  4. if (contentType.includes('application/json')) {
  5. const body = await request.json()
  6. return JSON.stringify(body)
  7. } else if (contentType.includes('application/text')) {
  8. const body = await request.text()
  9. return body
  10. } else if (contentType.includes('text/html')) {
  11. const body = await request.text()
  12. return body
  13. } else if (contentType.includes('form')) {
  14. const formData = await request.formData()
  15. let body = {}
  16. for (let entry of formData.entries()) {
  17. body[entry[0]] = entry[1]
  18. }
  19. return JSON.stringify(body)
  20. } else {
  21. let myBlob = await request.blob()
  22. var objectURL = URL.createObjectURL(myBlob)
  23. return objectURL
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement