workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

🐛 BUG: DELETE request with a body fails in `wrangler dev`

Open robinsloan opened this issue 3 years ago • 4 comments

What version of Wrangler are you using?

2.0.15

What operating system are you using?

Mac

Describe the Bug

I have a worker, authored in Typescript, that responds at a DELETE endpoint.

When I run the worker in production, with wrangler publish, requests to the DELETE endpoint work as expected.

When I run the worker in development, with wrangler dev, requests to the DELETE endpoint receive a 400 error immediately. Indeed, my FetchEvent handler is never triggered; my high-tech console.log statement in its first line is never emitted.

Here's the twist: if I switch to local development mode (with the shortcut l), requests to the DELETE endpoint once again work as expected.

I haven't encountered this behavior with any other HTTP verbs. So, there's something different about the way DELETE is treated by wrangler dev in its non-local mode.

Thanks for considering!

robinsloan avatar Jul 01 '22 17:07 robinsloan

That's extremely weird. I'm not able to reproduce this. I made a worker like so:

export default {
  fetch() {
    return new Response("Hello World!");
  },
};

and ran it with wrangler dev. In another tab, I made another script like so:

fetch("http://localhost:8787", { method: "DELETE" }).then(async (response) => {
  console.log("ok", response.ok);
  console.log(await response.text());
});

and ran it with node. It worked fine, and logged

ok true
Hello World!

as expected.

(I also tried with a service-worker format worker, like so

addEventListener("fetch", (event) => {
  event.respondWith(new Response("Hello World!"));
});

and it worked as expected)

So I don't think there's a problem in wrangler per se, but I can't be sure what the problem is here. Are you using a domain? Do you have something like Access or something else fronting that domain? If you could make a small git repo that reproduces this issue I'd be happy to help, but I can't say more without further details.

threepointone avatar Jul 02 '22 09:07 threepointone

Ah, I figured out the difference:

Non-local worker dev returns 400, never entering the worker code at all, when the DELETE request has a body. Local worker dev and the published worker process the request as expected.

And, yes, I know DELETE bodies are weird and undefined -- so, it would be fine for Workers to say, as a policy, "You can't use them, ever." It's the inconsistent handling that's confusing. (Although of course I hope the fix might be to make non-local dev simply accept them, just like the other two environments do…)

I made a small test project to verify this, and I'm happy to post it, but I don't think you'll need it: just add a body to your DELETE request and you'll see the pattern I described above.

robinsloan avatar Jul 02 '22 14:07 robinsloan

Well damn. Thanks for digging into this. I absolutely hate behaviour differences between dev and production environments. I'm going to escalate this internally, thanks so much for the added information. I'll leave this open until I have an update on our next steps.

threepointone avatar Jul 02 '22 15:07 threepointone

we've created an internal ticket to track this

lrapoport-cf avatar Sep 20 '22 20:09 lrapoport-cf

This hit me too and it was a surprise disruption to manual testing.

cendyne avatar Apr 22 '23 20:04 cendyne

@JacobMGEvans @mrbbot What's the status of this?

penalosa avatar Jun 16 '23 13:06 penalosa

@penalosa there is an internal ticket EW-6919 with discussion on this

lrapoport-cf avatar Jun 16 '23 15:06 lrapoport-cf

Hey everyone! 👋 Thanks for flagging this. In an effort to remove stale issues so we can have better signal on current friction points, we’re closing out issues that have not been updated within the last 6 months. If this is still a problem, please feel free to open a new issue referencing this one. Please be sure to include an updated summary and any additional context and we will review. Thank you!

mrbbot avatar Jan 10 '24 17:01 mrbbot