From c1f5a2acb2bcd6e9ba549bf5d3c3fd0c6789aeae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sun, 16 Sep 2012 14:58:57 +0200 Subject: Use cowboy_req:version/1 in cowboy_protocol where applicable More cleanup towards making cowboy_req:req() opaque. --- src/cowboy_protocol.erl | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/cowboy_protocol.erl') diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl index ad22141..ad0987b 100644 --- a/src/cowboy_protocol.erl +++ b/src/cowboy_protocol.erl @@ -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) -> -- cgit v1.2.3