Skip to content

Commit

Permalink
Add the private set_buffer/2 function 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 fc02b7f commit 5b56dd7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/cowboy_protocol.erl
Expand Up @@ -214,11 +214,13 @@ header(http_eoh, Req, State=#state{host_tokens=undefined,
error_terminate(400, State);
{{1, 0}, Req2} ->
Port = default_port(Transport:name()),
onrequest(Req2#http_req{host= <<>>, port=Port, buffer=Buffer},
onrequest(
cowboy_req:set_buffer(Buffer,
cowboy_req:set_host(<<>>, Port, <<>>, Req2)),
State#state{buffer= <<>>, host_tokens=[]})
end;
header(http_eoh, Req, State=#state{buffer=Buffer}) ->
onrequest(Req#http_req{buffer=Buffer}, State#state{buffer= <<>>});
onrequest(cowboy_req:set_buffer(Buffer, Req), State#state{buffer= <<>>});
header(_Any, _Req, State) ->
error_terminate(400, State).

Expand Down
6 changes: 6 additions & 0 deletions src/cowboy_req.erl
Expand Up @@ -106,6 +106,7 @@
-export([set_host/4]).
-export([set_connection/2]).
-export([add_header/3]).
-export([set_buffer/2]).

%% Misc API.
-export([compact/1]).
Expand Down Expand Up @@ -935,6 +936,11 @@ set_connection(RawConnection, Req=#http_req{headers=Headers}) ->
add_header(Name, Value, Req=#http_req{headers=Headers}) ->
Req#http_req{headers=[{Name, Value}|Headers]}.

%% @private
-spec set_buffer(binary(), Req) -> Req when Req::req().
set_buffer(Buffer, Req) ->
Req#http_req{buffer=Buffer}.

%% Misc API.

%% @doc Compact the request data by removing all non-system information.
Expand Down

0 comments on commit 5b56dd7

Please sign in to comment.