jshttp / type-is

Infer the content-type of a request.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Has body check returns `true` with `Content-Length: 0`

blakeembrey opened this issue · comments

Also with negative numbers, but 0 is the primary place I want to catch. There's no real difference between a missing content-length and content-length: 0, so I expect those would be treated the same. If this is a legitimate issue, I can open a PR. I noticed, however, that there's a test actually for the 0 handling - why?

References:

Ok, found #9. I'm still not sure that's expected behavior from a user point of view, it's kind of introducing subtle issues into client code, but please reopen if it's valid.

Unfortunately this issue is invalid. Your can find out more by reading the HTTP RFCs. The method determines if there is a body according to the HTTP specification. A request with Content-Length: 0 has a body, it is simply of length zero. Just like you would say a file exists even though the length is zero.

There's no real difference between a missing content-length and content-length: 0

And to touch on this comment, as far as HTTP as a protocol is concerned, there is a big difference between a header existing or not. You can find the rules for having a body in RFC 7230 section 3.3, by the way. I hope the analogy between a file existing and it's length makes sense in how having a body and the body's length are completely different things.

I would support @dougwilson on that. if client is explicitly sending content-length=0 then hasbody function should return false.

What is point of relying on content-length header if you don't care about the value in it.