0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 20:30:23 +00:00

Use cowboy_req:version/1 in cowboy_protocol where applicable

More cleanup towards making cowboy_req:req() opaque.
This commit is contained in:
Loïc Hoguin 2012-09-16 14:58:57 +02:00
parent 82d7e89ea2
commit c1f5a2acb2

View file

@ -220,16 +220,17 @@ header({http_header, _I, Field, _R, Value}, Req, State) ->
Field2 = format_header(Field),
parse_header(Req#http_req{headers=[{Field2, Value}|Req#http_req.headers]},
State);
%% The Host header is required in HTTP/1.1.
header(http_eoh, #http_req{version={1, 1}},
State=#state{host_tokens=undefined}) ->
error_terminate(400, State);
%% It is however optional in HTTP/1.0.
header(http_eoh, Req=#http_req{version={1, 0}, transport=Transport},
State=#state{buffer=Buffer, host_tokens=undefined}) ->
Port = default_port(Transport:name()),
onrequest(Req#http_req{host= <<>>, port=Port, buffer=Buffer},
State#state{buffer= <<>>, host_tokens=[]});
%% The Host header is required in HTTP/1.1 and optional in HTTP/1.0.
header(http_eoh, Req, State=#state{host_tokens=undefined,
buffer=Buffer, transport=Transport}) ->
case cowboy_req:version(Req) of
{{1, 1}, _} ->
error_terminate(400, State);
{{1, 0}, Req2} ->
Port = default_port(Transport:name()),
onrequest(Req2#http_req{host= <<>>, port=Port, buffer=Buffer},
State#state{buffer= <<>>, host_tokens=[]})
end;
header(http_eoh, Req, State=#state{buffer=Buffer}) ->
onrequest(Req#http_req{buffer=Buffer}, State#state{buffer= <<>>});
header(_Any, _Req, State) ->