jshttp / type-is

Infer the content-type of a request.
MIT License
226 stars 32 forks source link

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

Closed blakeembrey closed 8 years ago

blakeembrey commented 8 years ago

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:

blakeembrey commented 8 years ago

Ok, found https://github.com/jshttp/type-is/issues/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.

dougwilson commented 8 years ago

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.

dougwilson commented 8 years ago

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.

indolent-developer commented 5 years ago

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.