3

HTTP/1.1 servers default to the Keep-Alive setting of the Connection header. Why then do most browsers include Connection: Keep-Alive in their requests even when they know that the target server supports HTTP/1.1?

AComputer
  • 519
  • 2
  • 10
  • 21

2 Answers2

3

Browsers usually don't keep a cache of metadata about the servers they've contacted in the past, and even if they did, they'd have to account for server farms that have different versions of HTTP, intermediaries (especially "transparent" proxies), and so forth.

As such, they've made a judgement call that it's just easier to always send Connection: keep-alive, at least on the first request in a connection.

Mark Nottingham
  • 5,546
  • 1
  • 25
  • 21
1

The question doesn't make sense. The browser doesn't know what the server supports until after it has submitted the request and obtained a response.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • True, the browser client doesn't know in advance if the server supports `keep-alive`. But, the browser can be optimistic and make the `keep-alive` request to see if the server supports it. According to [this answer](http://stackoverflow.com/a/20764180/1497596), if the server supports `keep-alive`, it will honor the client's `keep-alive` request and return `Connection: keep-alive` to the client. Otherwise, my interpretation is that the server will return `Connection: close`. – DavidRR Jan 08 '15 at 16:20
  • @DavidRR Of course it can, and it does, and that's what the question is about, aprt from the part about 'when they know that the target server supports HTTP/1.1' that doesn't make sense. – user207421 Jul 24 '15 at 08:17
  • Understood. I think you could improve your answer by saying: *"The browser doesn't know what* ***version of HTTP*** *the server supports until after it has submitted the request... So, it follows then that before hearing back from the server, the browser cannot make any assumptions about whether the server supports `keep-alive`.* I think it would also be helpful to explicitly address whether the HTTP/1.1 standard *mandates* support for `keep-alive`. – DavidRR Jul 24 '15 at 14:01