diff options
author | Loïc Hoguin <[email protected]> | 2012-09-16 14:58:57 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2012-09-17 13:57:28 +0200 |
commit | c1f5a2acb2bcd6e9ba549bf5d3c3fd0c6789aeae (patch) | |
tree | 79b8164b56e6b80b73eb8cfd0e6665c055dbcb89 | |
parent | 82d7e89ea2e294176a42a46e67fa42df67ae7b21 (diff) | |
download | cowboy-c1f5a2acb2bcd6e9ba549bf5d3c3fd0c6789aeae.tar.gz cowboy-c1f5a2acb2bcd6e9ba549bf5d3c3fd0c6789aeae.tar.bz2 cowboy-c1f5a2acb2bcd6e9ba549bf5d3c3fd0c6789aeae.zip |
Use cowboy_req:version/1 in cowboy_protocol where applicable
More cleanup towards making cowboy_req:req() opaque.
-rw-r--r-- | src/cowboy_protocol.erl | 21 |
1 files changed, 11 insertions, 10 deletions
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) -> |