1

HTTP specification (RFC2616) has the following phrase:

If a Transfer-Encoding header field (section 14.41) is present and has any value other than "identity", then the transfer-length is defined by use of the "chunked" transfer-coding (section 3.6), unless the message is terminated by closing the connection.

How can I detect that the message is "terminated by closing the connection"? Is it enough to check the "Connection" field for value "close"?

Dmitry Poroh
  • 3,705
  • 20
  • 34

1 Answers1

0

I think that the RFC points to the TCP connection, when you read 0 bytes from the socket, the other side has closed the connection.

More: Can read() function on a connected socket return zero bytes?

Community
  • 1
  • 1
  • If (Transfer-encoding present && not equal to identity && not connection is terminated by closing the connection) then I should decoded it as chunked-encoded. How can I detect last condition before peer is closed the connection? – Dmitry Poroh Jul 24 '12 at 13:05
  • I think that the idea of the "unless the message is terminated by closing the connection." phrase defines the exit condition of the chunk treatment (beacause a chunk may come in different packages, when a connection falls in chunk transfer state, it's in this state (appending the chunks) until the last chunk is detectd (length 0) or the connection is closed).. Something like If (Transfer-encoding present && not equal to identity){while (not end of chunk OR not end of connection){do the neccessary stuff with the chunk}}; – Jon Ander Ortiz Durántez Jul 24 '12 at 13:28
  • This sounds very strange for me. I think that I shouldn't believe message body unless the last chunk is received. – Dmitry Poroh Jul 24 '12 at 13:40