aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-09-16 16:04:16 +0200
committerLoïc Hoguin <[email protected]>2012-09-17 13:57:28 +0200
commit350d4ae3f2e9973b3638b06c7092370afa08e634 (patch)
treeb54a486bb8476a8058a9213a101cc2e2ad8a637c
parent6dbc1f9ef98eda6cfdffc0a47b68fb50eeb3863a (diff)
downloadcowboy-350d4ae3f2e9973b3638b06c7092370afa08e634.tar.gz
cowboy-350d4ae3f2e9973b3638b06c7092370afa08e634.tar.bz2
cowboy-350d4ae3f2e9973b3638b06c7092370afa08e634.zip
Add the private function set_host/4 used by cowboy_protocol
-rw-r--r--src/cowboy_protocol.erl16
-rw-r--r--src/cowboy_req.erl11
2 files changed, 17 insertions, 10 deletions
diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl
index 9b04ec3..8323b80 100644
--- a/src/cowboy_protocol.erl
+++ b/src/cowboy_protocol.erl
@@ -182,20 +182,16 @@ wait_header(Req, State=#state{socket=Socket,
-spec header({http_header, integer(), cowboy_http:header(), any(), binary()}
| http_eoh, cowboy_req:req(), #state{}) -> ok.
-header({http_header, _I, 'Host', _R, RawHost}, Req=#http_req{
- transport=Transport}, State=#state{host_tokens=undefined}) ->
+header({http_header, _I, 'Host', _R, RawHost}, Req,
+ State=#state{host_tokens=undefined, transport=Transport}) ->
RawHost2 = cowboy_bstr:to_lower(RawHost),
case catch cowboy_dispatcher:split_host(RawHost2) of
- {HostTokens, RawHost3, undefined} ->
+ {HostTokens, Host, undefined} ->
Port = default_port(Transport:name()),
- parse_header(Req#http_req{
- host=RawHost3, port=Port,
- headers=[{'Host', RawHost}|Req#http_req.headers]},
+ parse_header(cowboy_req:set_host(Host, Port, RawHost, Req),
State#state{host_tokens=HostTokens});
- {HostTokens, RawHost3, Port} ->
- parse_header(Req#http_req{
- host=RawHost3, port=Port,
- headers=[{'Host', RawHost}|Req#http_req.headers]},
+ {HostTokens, Host, Port} ->
+ parse_header(cowboy_req:set_host(Host, Port, RawHost, Req),
State#state{host_tokens=HostTokens});
{'EXIT', _Reason} ->
error_terminate(400, State)
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index 80d68a9..08e4155 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -102,6 +102,9 @@
-export([upgrade_reply/3]).
-export([ensure_response/2]).
+%% Private setter/getter API.
+-export([set_host/4]).
+
%% Misc API.
-export([compact/1]).
-export([lock/1]).
@@ -908,6 +911,14 @@ ensure_response(#http_req{socket=Socket, transport=Transport,
Transport:send(Socket, <<"0\r\n\r\n">>),
ok.
+%% Private setter/getter API.
+
+%% @private
+-spec set_host(binary(), inet:port_number(), binary(), Req)
+ -> Req when Req::req().
+set_host(Host, Port, RawHost, Req=#http_req{headers=Headers}) ->
+ Req#http_req{host=Host, port=Port, headers=[{'Host', RawHost}|Headers]}.
+
%% Misc API.
%% @doc Compact the request data by removing all non-system information.