Skip to content

Commit

Permalink
Add the private get_connection/1 function used by cowboy_protocol
Browse files Browse the repository at this point in the history
This removes cowboy_protocol's dependency on http.hrl!
  • Loading branch information
essen committed Sep 17, 2012
1 parent cf0e905 commit 58edd4c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/cowboy_protocol.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
-export([parse_request/1]).
-export([handler_loop/3]).

-include("http.hrl").
-include_lib("eunit/include/eunit.hrl").

-record(state, {
Expand Down Expand Up @@ -390,7 +389,7 @@ terminate_request(HandlerState, Req, State) ->
next_request(Req, State, HandlerRes).

-spec next_request(cowboy_req:req(), #state{}, any()) -> ok.
next_request(Req=#http_req{connection=Conn}, State=#state{
next_request(Req, State=#state{
req_keepalive=Keepalive}, HandlerRes) ->
cowboy_req:ensure_response(Req, 204),
{BodyRes, Buffer} = case cowboy_req:skip_body(Req) of
Expand All @@ -399,7 +398,7 @@ next_request(Req=#http_req{connection=Conn}, State=#state{
end,
%% Flush the resp_sent message before moving on.
receive {cowboy_req, resp_sent} -> ok after 0 -> ok end,
case {HandlerRes, BodyRes, Conn} of
case {HandlerRes, BodyRes, cowboy_req:get_connection(Req)} of
{ok, ok, keepalive} ->
?MODULE:parse_request(State#state{
buffer=Buffer, host_tokens=undefined, path_tokens=undefined,
Expand Down
6 changes: 6 additions & 0 deletions src/cowboy_req.erl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
-export([set_bindings/4]).
-export([get_resp_state/1]).
-export([get_buffer/1]).
-export([get_connection/1]).

%% Misc API.
-export([compact/1]).
Expand Down Expand Up @@ -961,6 +962,11 @@ get_resp_state(#http_req{resp_state=RespState}) ->
get_buffer(#http_req{buffer=Buffer}) ->
Buffer.

%% @private
-spec get_connection(req()) -> keepalive | close.
get_connection(#http_req{connection=Connection}) ->
Connection.

%% Misc API.

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

0 comments on commit 58edd4c

Please sign in to comment.