If an HTTP / 1.0 client requests Connection: keep-alive, will it understand the chunked encoding?

If my HTTP server receives an HTTP / 1.0 request with the heading "Connection: keep-alive", can I say that the client will understand "Transfer-Encoding: chunked"?

Essentially, I'm trying to decide whether to respect the "Connection: keep-alive" header from HTTP / 1.0 clients. If I read it, then I have to use the encoding for the response, because I cannot buffer the entire response to calculate the Content-Length header.

If it is unsafe to expect that the HTTP / 1.0 client that requests “Connection: keep-alive” will also understand the encoding, then I will have to close the connection after each response. (Or am I missing something?)

+3
source share
3 answers

This is the ultimate no. Quote from specification:

However, a persistent connection to an HTTP / 1.0 client cannot use encrypted transmission encoding, and therefore MUST use a Content-Length to mark the end border of each message.

- RFC 2068 §19.7.1

+5
source

Definitely not, considering that Transfer-Encoding- only in HTTP 1.1. Given your situation, I don’t think you can really support the header Connection: keep-alivefor the HTTP 1.0 client (for your use case, otherwise it is supported by HTTP 1.0). You should just ignore it and close the connection. You will be safe because it is just an optimization.

+4

HTTP 1.0 . Keep-alive HTTP 1.0 1.1.

, , , , , .

  • HTTP 1.0, Keep-Alive , , .

  • HTTP 1.0 , chunked transfer-encoding, chunked HTTP 1.0. , , .

    HTTP 1.0 keep-alive, -.

  • keep-alive chunked transfer-encoding, Content-Length . , keep-alive HTTP 1.0, , Content-Length. , script, .

    , keep-alive . , , .

  • HTTP 1.1 , , HTTP 1.1 HTTP/1.1 Keep-Alive .

    In practice, the client can still send a keep-alive header so that it can use keep-alive, even if the server only supports HTTP 1.0. If the server supports HTTP 1.1 or higher, this header will be ignored, and the HTTP / 1.1 protocol indicator takes precedence. Note. I believe that it is very rare for a server today to not support HTTP 1.1 or higher, but to support support, so sending will be rarely useful.

+3
source

All Articles