mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-16 05:00:24 +00:00
Remove the connection information from the HTTP protocol state
Use the Req connection information instead.
This commit is contained in:
parent
547107cfb9
commit
ee77ecec92
1 changed files with 6 additions and 9 deletions
|
@ -47,7 +47,6 @@
|
||||||
req_empty_lines = 0 :: integer(),
|
req_empty_lines = 0 :: integer(),
|
||||||
max_empty_lines :: integer(),
|
max_empty_lines :: integer(),
|
||||||
timeout :: timeout(),
|
timeout :: timeout(),
|
||||||
connection = keepalive :: keepalive | close,
|
|
||||||
buffer = <<>> :: binary()
|
buffer = <<>> :: binary()
|
||||||
}).
|
}).
|
||||||
|
|
||||||
|
@ -103,15 +102,13 @@ request({http_request, Method, {abs_path, AbsPath}, Version},
|
||||||
ConnAtom = version_to_connection(Version),
|
ConnAtom = version_to_connection(Version),
|
||||||
parse_header(#http_req{socket=Socket, transport=Transport,
|
parse_header(#http_req{socket=Socket, transport=Transport,
|
||||||
connection=ConnAtom, method=Method, version=Version,
|
connection=ConnAtom, method=Method, version=Version,
|
||||||
path=Path, raw_path=RawPath, raw_qs=Qs},
|
path=Path, raw_path=RawPath, raw_qs=Qs}, State);
|
||||||
State#state{connection=ConnAtom});
|
|
||||||
request({http_request, Method, '*', Version},
|
request({http_request, Method, '*', Version},
|
||||||
State=#state{socket=Socket, transport=Transport}) ->
|
State=#state{socket=Socket, transport=Transport}) ->
|
||||||
ConnAtom = version_to_connection(Version),
|
ConnAtom = version_to_connection(Version),
|
||||||
parse_header(#http_req{socket=Socket, transport=Transport,
|
parse_header(#http_req{socket=Socket, transport=Transport,
|
||||||
connection=ConnAtom, method=Method, version=Version,
|
connection=ConnAtom, method=Method, version=Version,
|
||||||
path='*', raw_path= <<"*">>, raw_qs= <<>>},
|
path='*', raw_path= <<"*">>, raw_qs= <<>>}, State);
|
||||||
State#state{connection=ConnAtom});
|
|
||||||
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">>},
|
request({http_error, <<"\r\n">>},
|
||||||
|
@ -164,8 +161,7 @@ header({http_header, _I, 'Host', _R, _V}, Req, State) ->
|
||||||
header({http_header, _I, 'Connection', _R, Connection}, Req, State) ->
|
header({http_header, _I, 'Connection', _R, Connection}, Req, State) ->
|
||||||
ConnAtom = connection_to_atom(Connection),
|
ConnAtom = connection_to_atom(Connection),
|
||||||
parse_header(Req#http_req{connection=ConnAtom,
|
parse_header(Req#http_req{connection=ConnAtom,
|
||||||
headers=[{'Connection', Connection}|Req#http_req.headers]},
|
headers=[{'Connection', Connection}|Req#http_req.headers]}, State);
|
||||||
State#state{connection=ConnAtom});
|
|
||||||
header({http_header, _I, Field, _R, Value}, Req, State) ->
|
header({http_header, _I, Field, _R, Value}, Req, State) ->
|
||||||
Field2 = format_header(Field),
|
Field2 = format_header(Field),
|
||||||
parse_header(Req#http_req{headers=[{Field2, Value}|Req#http_req.headers]},
|
parse_header(Req#http_req{headers=[{Field2, Value}|Req#http_req.headers]},
|
||||||
|
@ -252,11 +248,12 @@ handler_terminate(HandlerState, Req, #state{handler={Handler, Opts}}) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec next_request(any(), #http_req{}, #state{}) -> ok.
|
-spec next_request(any(), #http_req{}, #state{}) -> ok.
|
||||||
next_request(HandlerState, Req=#http_req{buffer=Buffer}, State) ->
|
next_request(HandlerState, Req=#http_req{connection=Conn, buffer=Buffer},
|
||||||
|
State) ->
|
||||||
HandlerRes = handler_terminate(HandlerState, Req, State),
|
HandlerRes = handler_terminate(HandlerState, Req, State),
|
||||||
BodyRes = ensure_body_processed(Req),
|
BodyRes = ensure_body_processed(Req),
|
||||||
RespRes = ensure_response(Req),
|
RespRes = ensure_response(Req),
|
||||||
case {HandlerRes, BodyRes, RespRes, State#state.connection} of
|
case {HandlerRes, BodyRes, RespRes, Conn} of
|
||||||
{ok, ok, ok, keepalive} ->
|
{ok, ok, ok, keepalive} ->
|
||||||
?MODULE:parse_request(State#state{
|
?MODULE:parse_request(State#state{
|
||||||
buffer=Buffer, req_empty_lines=0});
|
buffer=Buffer, req_empty_lines=0});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue