From b10b34a8f204ed409a6fc936e199557bfe3b0975 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Tue, 14 Jan 2014 13:30:58 -0500 Subject: Support ad-hoc keep-alive for HTTP/1.0 Clients Only go for keep-alive if they submit a 'connection: keep-alive' header in the request, keep behaviour the same otherwise. The new RFC 7230 (http://tools.ietf.org/html/rfc7230#section-6.3) states: If the received protocol is HTTP/1.0, the "keep-alive" connection option is present, the recipient is not a proxy, and the recipient wishes to honor the HTTP/1.0 "keep-alive" mechanism, the connection will persist after the current response; Even though clients are discouraged from doing so in Appendix A.1.2 (http://tools.ietf.org/html/rfc7230#appendix-A.1.2) --- src/cowboy_req.erl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl index 1394e72..981b321 100644 --- a/src/cowboy_req.erl +++ b/src/cowboy_req.erl @@ -174,13 +174,16 @@ new(Socket, Transport, Peer, Method, Path, Query, method=Method, path=Path, qs=Query, version=Version, headers=Headers, host=Host, port=Port, buffer=Buffer, resp_compress=Compress, onresponse=OnResponse}, - case CanKeepalive and (Version =:= 'HTTP/1.1') of + case CanKeepalive of false -> Req#http_req{connection=close}; true -> case lists:keyfind(<<"connection">>, 1, Headers) of false -> - Req; %% keepalive + case Version of + 'HTTP/1.1' -> Req; %% keepalive + 'HTTP/1.0' -> Req#http_req{connection=close} + end; {_, ConnectionHeader} -> Tokens = cow_http_hd:parse_connection(ConnectionHeader), Connection = connection_to_atom(Tokens), -- cgit v1.2.3