#Unable to get body in PUT request (works in POST)

8 messages · Page 1 of 1 (latest)

soft cove
#

Sample code:

addEventListener("fetch", (event) => {
  event.respondWith(
    handleRequest(event.request).catch(
      (err) => new Response(err.stack, { status: 500 })
    )
  );
}); 

async function handleRequest(request) {
  let url=new URL(request.url)
  console.log(request.bodyUsed);
  console.log("fooBar");
  console.log(await request.text());
  url.host = "XXX.m.pipedream.net";
  const forwardRequest=new Request(url, request)
  return fetch(forwardRequest)
}

I'm unable to identify why PUT does not give me any body while POST does work perfectly fine. For PUT request.body is always null EVEN if it contains body.

Yes I know that the code above does not make much sense but it's only an example.

soft cove
#

Is it some known bug / limitation of workers or what? Why does it work perfectly ok with POST but not with PUT requests?

modern yoke
soft cove
#

Its opposite actually:) the request.text() is empty here.

modern yoke
#

I'm getting a 404, but that appears to be coming from your origin

soft cove
#

Hmm I'll check later... Weird...

#

Thanks