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.

https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

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: https://fetch.spec.whatwg.org/#concept-method-normalize

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

2 Likes

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!