mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Default the connection to keep-alive on HTTP/1.1 and close on 1.0.
This commit is contained in:
parent
896b854908
commit
6fad3f7824
1 changed files with 12 additions and 5 deletions
|
@ -66,14 +66,17 @@ request({http_request, Method, {abs_path, AbsPath}, Version},
|
||||||
State=#state{socket=Socket, transport=Transport}) ->
|
State=#state{socket=Socket, transport=Transport}) ->
|
||||||
{Path, RawPath, Qs} = cowboy_dispatcher:split_path(AbsPath),
|
{Path, RawPath, Qs} = cowboy_dispatcher:split_path(AbsPath),
|
||||||
{ok, Peer} = Transport:peername(Socket),
|
{ok, Peer} = Transport:peername(Socket),
|
||||||
wait_header(#http_req{socket=Socket, transport=Transport, method=Method,
|
ConnAtom = version_to_connection(Version),
|
||||||
version=Version, peer=Peer, path=Path, raw_path=RawPath, raw_qs=Qs},
|
wait_header(#http_req{socket=Socket, transport=Transport,
|
||||||
State);
|
connection=ConnAtom, method=Method, version=Version,
|
||||||
|
peer=Peer, path=Path, raw_path=RawPath, raw_qs=Qs}, State);
|
||||||
request({http_request, Method, '*', Version},
|
request({http_request, Method, '*', Version},
|
||||||
State=#state{socket=Socket, transport=Transport}) ->
|
State=#state{socket=Socket, transport=Transport}) ->
|
||||||
{ok, Peer} = Transport:peername(Socket),
|
{ok, Peer} = Transport:peername(Socket),
|
||||||
wait_header(#http_req{socket=Socket, transport=Transport, method=Method,
|
ConnAtom = version_to_connection(Version),
|
||||||
version=Version, peer=Peer, path='*', raw_path="*", raw_qs=[]}, State);
|
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) ->
|
request({http_request, _Method, _URI, _Version}, State) ->
|
||||||
error_terminate(501, State);
|
error_terminate(501, State);
|
||||||
request({http_error, "\r\n"}, State) ->
|
request({http_error, "\r\n"}, State) ->
|
||||||
|
@ -180,6 +183,10 @@ next_request(State=#state{connection=close}) ->
|
||||||
|
|
||||||
%% Internal.
|
%% 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.
|
-spec connection_to_atom(Connection::string()) -> keepalive | close.
|
||||||
connection_to_atom(Connection) ->
|
connection_to_atom(Connection) ->
|
||||||
case string:to_lower(Connection) of
|
case string:to_lower(Connection) of
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue