Skip to content

Commit

Permalink
Add the private function set_host/4 used by cowboy_protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
essen committed Sep 17, 2012
1 parent 6dbc1f9 commit 350d4ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/cowboy_protocol.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions src/cowboy_req.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 350d4ae

Please sign in to comment.