Case sensitive HTTP methods using fetch in cloudflare worker?

Recently while copying some JS from the client side frontend to a CFW I encountered this little oddity…

fetch(url, { method: 'post' })

Works fine in client side JS, but fails with an exception in a CFW.

TypeError: Invalid HTTP method string: post

You must use

fetch(url, { method: 'POST' })

Does it make sense to enforce case sensitivity here? What is the reasoning?

HTTP method definitions are always upper-case, CF is only adhering to the standard.

1 Like

As @thomas4 mentioned, HTTP methods are case-sensitive, which I think is why we implemented it this way.

However, the Fetch specification automatically uppercases certain HTTP method names:

So this is actually a bug in our JS API. We have a ticket open to fix it.


Fun, productive and educational for everyone. Thank you @thomas4 @harris :hugs:

1 Like

@harris @mattdlockyer

From Cloudflare’s side, we’ve fixed this bug and have rolled out the new changes. Thanks for flagging this as an issue Matt!

1 Like

Happy to help, love workers!