문제

My client sets the following headers:

Transfer-Encoding: chunked
Connection: Keep-Alive

When I retrieve responses I receive a Transfer-Encoding: chunked header but no Connection: Keep-Alive header. For this reason I believe I may only be receiving a partial response in my client.

Now my question is:

Is it mandatory to set the Connection: Keep-Alive property in HTTP/1.1 ?

도움이 되었습니까?

해결책

In short, no. In the absence of a Connection header for messages adhering to HTTP/1.1 the default is a persistent Keep-Alive connection. If a connection header is present both parties should act accordingly given that header's value.

As stated by RFC 2616 Section 8.1.2:

A significant difference between HTTP/1.1 and earlier versions of HTTP is that persistent connections are the default behavior of any HTTP connection. That is, unless otherwise indicated, the client SHOULD assume that the server will maintain a persistent connection, even after error responses from the server.

Of course, this doesn't prevent you from explicitly setting a Connection: close header if you wish to close the connection once the transfer completes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top