is an HTTP/1.1 request implicitly keep-alive by de

2019-02-03 08:32发布

问题:

Solved: pasting the bytes here made me realise that I was missing empty lines between chunks...


Does an HTTP/1.1 request need to specify a Connection: keep-alive header, or is it always keep-alive by default?

This guide made me think it would; that, when my http server gets a 1.1 request, it is keep-alive unless explicitly receiving a Connection: close header.

I ask since my the different client behaviour of ab and httperf is driving me mad enough to wonder my sanity on this one...


Here's what httperf --hog --port 42042 --print-reply body sends:

GET / HTTP/1.1
User-Agent: httperf/0.9.0
Host: localhost

And here's my server's response:

HTTP/1.1 200 OK
Connection: keep-alive
Transfer-Encoding: chunked
Content-Length: 18

12
Hello World      1
0

httpref promptly prints out the response, but then just sits there, neither side closing the connection and httpref not exiting.

Where's my bug?

回答1:

From 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.



标签: http