aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-03-20 00:09:15 +0100
committerLoïc Hoguin <[email protected]>2011-03-20 00:09:15 +0100
commit6fad3f7824763629c5c2a32d890f1091465408bc (patch)
tree0ff85871a0e4da1fba0aa02d70343acd9b1be6ba
parent896b854908319a1f7e7ff186980ba09a7a6c5802 (diff)
downloadcowboy-6fad3f7824763629c5c2a32d890f1091465408bc.tar.gz
cowboy-6fad3f7824763629c5c2a32d890f1091465408bc.tar.bz2
cowboy-6fad3f7824763629c5c2a32d890f1091465408bc.zip
Default the connection to keep-alive on HTTP/1.1 and close on 1.0.
-rw-r--r--src/cowboy_http_protocol.erl17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/cowboy_http_protocol.erl b/src/cowboy_http_protocol.erl
index 1392ea1..4a74cb5 100644
--- a/src/cowboy_http_protocol.erl
+++ b/src/cowboy_http_protocol.erl
@@ -66,14 +66,17 @@ request({http_request, Method, {abs_path, AbsPath}, Version},
State=#state{socket=Socket, transport=Transport}) ->
{Path, RawPath, Qs} = cowboy_dispatcher:split_path(AbsPath),
{ok, Peer} = Transport:peername(Socket),
- wait_header(#http_req{socket=Socket, transport=Transport, method=Method,
- version=Version, peer=Peer, path=Path, raw_path=RawPath, raw_qs=Qs},
- State);
+ ConnAtom = version_to_connection(Version),
+ wait_header(#http_req{socket=Socket, transport=Transport,
+ connection=ConnAtom, method=Method, version=Version,
+ peer=Peer, path=Path, raw_path=RawPath, raw_qs=Qs}, State);
request({http_request, Method, '*', Version},
State=#state{socket=Socket, transport=Transport}) ->
{ok, Peer} = Transport:peername(Socket),
- wait_header(#http_req{socket=Socket, transport=Transport, method=Method,
- version=Version, peer=Peer, path='*', raw_path="*", raw_qs=[]}, State);
+ ConnAtom = version_to_connection(Version),
+ wait_header(#http_req{socket=Socket, transport=Transport,
+ connection=ConnAtom, method=Method, version=Version,
+ peer=Peer, path='*', raw_path="*", raw_qs=[]}, State);
request({http_request, _Method, _URI, _Version}, State) ->
error_terminate(501, State);
request({http_error, "\r\n"}, State) ->
@@ -180,6 +183,10 @@ next_request(State=#state{connection=close}) ->
%% Internal.
+-spec version_to_connection(Version::http_version()) -> keepalive | close.
+version_to_connection({1, 1}) -> keepalive;
+version_to_connection(_Any) -> close.
+
-spec connection_to_atom(Connection::string()) -> keepalive | close.
connection_to_atom(Connection) ->
case string:to_lower(Connection) of