diff options
-rw-r--r-- | src/cowboy_req.erl | 7 | ||||
-rw-r--r-- | test/http_SUITE.erl | 28 |
2 files changed, 33 insertions, 2 deletions
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), diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl index e5a9256..0417ad0 100644 --- a/test/http_SUITE.erl +++ b/test/http_SUITE.erl @@ -426,6 +426,34 @@ http10_hostless(Config) -> [{port, Port10}|Config]), cowboy:stop_listener(http10_hostless). +http10_keepalive_default(Config) -> + Normal = "GET / HTTP/1.0\r\nhost: localhost\r\n\r\n", + Client = raw_open(Config), + ok = raw_send(Client, Normal), + case catch raw_recv_head(Client) of + {'EXIT', _} -> error(closed); + _ -> ok + end, + ok = raw_send(Client, Normal), + case catch raw_recv_head(Client) of + {'EXIT', _} -> closed; + _ -> error(not_closed) + end. + +http10_keepalive_forced(Config) -> + Keepalive = "GET / HTTP/1.0\r\nhost: localhost\r\nConnection: keep-alive\r\n\r\n", + Client = raw_open(Config), + ok = raw_send(Client, Keepalive), + case catch raw_recv_head(Client) of + {'EXIT', _} -> error(closed); + _ -> ok + end, + ok = raw_send(Client, Keepalive), + case catch raw_recv_head(Client) of + {'EXIT', Err} -> error({closed, Err}); + _ -> ok + end. + keepalive_max(Config) -> {ConnPid, MRef} = gun_monitor_open(Config), Refs = [gun:get(ConnPid, "/", [{<<"connection">>, <<"keep-alive">>}]) |