4

If the response has a body / can have body (i.e status code is not 204 or 304), should it always have either content-length or Transfer-Encoding in the response header. In the spec it is not very clear.

In my scenario I have a body without content-length or transfer encoding header, so the curl is keep on waiting no chunk, no close, no size. Assume close to signal end while other clients (like postman) are getting the content without hanging.

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
user392919
  • 53
  • 2
  • 7
  • if other clients can do that without waiting for the close, they probably get a different response from the server... – Daniel Stenberg Apr 25 '16 at 07:01
  • The difference between other clients and curl is, when postman sends a request it adds the headers `"Accept: */*", "Accept-Encoding: gzip, deflate, sdch", "Accept-Language: en-US,en;q=0.8"` so when receiving the response the server sends with `Transfer-Encoding`. – user392919 Apr 26 '16 at 04:38

2 Answers2

3

Transfer-Encoding is a HTTP/1.1 addition. So, that version of the protocol seems relevant here.

It states about Content-Length:

it SHOULD be sent whenever the message's length can be determined prior to being transferred, unless this is prohibited by the rules in section 4.4.

This clearly indicates that it is not required to be sent.

With Transfer-Encoding the standard states:

The Transfer-Encoding general-header field indicates what (if any) type of transformation has been applied to the message body in order to safely transfer it between the sender and the recipient.

This allows for leaving out the header field if no transfer encoding is being applied.

From this follows: both headers may validly be missing from a response.

In your case curl is telling what it does: It is waiting for the remote side to close the connection for knowing the data has been fully received.

You should provide your curl flags and the relevant communications from -v to allow more insight in why other tools seem to get a better idea on why there is no more data before EOF has been encountered.

rpy
  • 3,953
  • 2
  • 20
  • 31
  • You're citing an obsolete spec. – Julian Reschke Apr 25 '16 at 07:01
  • @Julian Reschke: you are right, the cited text is from an older version of HTTP/1.1. As I did not claim a specific version what is the logical difference with the wording cited and the wording from RFC7230 that is the latest version I know of? (besides the numbering of the sections). The latest wording seems not to contradict the cited statements. – rpy Apr 25 '16 at 07:35
  • I agree that the result is the same; but I also believe that citing obsolete specs should be avoided; in particular as for RFC 7230, a lot of time was invested to answer questions like these. – Julian Reschke Apr 25 '16 at 07:39
2

RFC 7230 has a very detailed description of this (see Section 3.3.3). In particular, the last point:

  1. Otherwise, this is a response message without a declared message body length, so the message body length is determined by the number of octets received prior to the server closing the connection.
Julian Reschke
  • 40,156
  • 8
  • 95
  • 98