Skip to content

Fetch blocks Content-Length: 0 with GET request #1249

@bdw429s

Description

@bdw429s

This is similar to #795 but different. 795 is asking to actually send a body with a GET request. I've noticed that sending a GET request even with NO body is still blocked if there is a Content-Length header present, even if the length is set to 0. i.e.

Content-Length: 0

I've come across a handful of older HTTP clients who do this just as a matter of course and it causes issues specifically in CloudFlare workers were developers are proxying the original request through the Fetch API. The following error is thrown:

Request with a GET or HEAD method cannot have a body.

And just to be very clear-- there is no actual body in my case. There is only a Content-Length header of 0.

https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.2 says

A user agent SHOULD NOT send a Content-Length header field when the request message does not contain a payload body and the method semantics do not anticipate such a body.

The key words here are "SHOULD NOT". Per https://datatracker.ietf.org/doc/html/rfc2119 "SHOULD NOT" means the behavior is not recommended, but is not striclty prohibited by the spec. And since the spec does not say "MUST NOT", libraries such as the Ruby httprb Gem refuse to change the behavior of their code as they claim having a content-length header is not strictly forbidden in the spec. See the thread in this ticket here:

httprb/http#487

My suggestion is that an content-length of 0 should simply be ignored for GET requests as the mere inclusion of the header is not in violation of the spec. I'm fine if actual request bodies are still rejected.

I am not a direct user of either of these libraries, but a stranded third party trying to work through this issue for context:

https://meta.discourse.org/t/link-preview-http-get-breaks-spec/200996

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions