aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cowboy.erl3
-rw-r--r--src/cowboy_protocol.erl22
-rw-r--r--src/cowboy_spdy.erl27
3 files changed, 9 insertions, 43 deletions
diff --git a/src/cowboy.erl b/src/cowboy.erl
index 8e9232f..af9f1b3 100644
--- a/src/cowboy.erl
+++ b/src/cowboy.erl
@@ -34,9 +34,6 @@
-type http_version() :: 'HTTP/1.1' | 'HTTP/1.0'.
-export_type([http_version/0]).
--type onrequest_fun() :: fun((Req) -> Req).
--export_type([onrequest_fun/0]).
-
-type onresponse_fun() ::
fun((http_status(), http_headers(), iodata(), Req) -> Req).
-export_type([onresponse_fun/0]).
diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl
index 1026d28..a5873ea 100644
--- a/src/cowboy_protocol.erl
+++ b/src/cowboy_protocol.erl
@@ -32,7 +32,6 @@
| {max_keepalive, non_neg_integer()}
| {max_request_line_length, non_neg_integer()}
| {middlewares, [module()]}
- | {onrequest, cowboy:onrequest_fun()}
| {onresponse, cowboy:onresponse_fun()}
| {timeout, timeout()}].
-export_type([opts/0]).
@@ -43,7 +42,6 @@
middlewares :: [module()],
compress :: boolean(),
env :: cowboy_middleware:env(),
- onrequest :: undefined | cowboy:onrequest_fun(),
onresponse = undefined :: undefined | cowboy:onresponse_fun(),
max_empty_lines :: non_neg_integer(),
req_keepalive = 1 :: non_neg_integer(),
@@ -85,7 +83,6 @@ init(Ref, Socket, Transport, Opts) ->
MaxRequestLineLength = get_value(max_request_line_length, Opts, 4096),
Middlewares = get_value(middlewares, Opts, [cowboy_router, cowboy_handler]),
Env = [{listener, Ref}|get_value(env, Opts, [])],
- OnRequest = get_value(onrequest, Opts, undefined),
OnResponse = get_value(onresponse, Opts, undefined),
Timeout = get_value(timeout, Opts, 5000),
ok = ranch:accept_ack(Ref),
@@ -95,8 +92,7 @@ init(Ref, Socket, Transport, Opts) ->
max_request_line_length=MaxRequestLineLength,
max_header_name_length=MaxHeaderNameLength,
max_header_value_length=MaxHeaderValueLength, max_headers=MaxHeaders,
- onrequest=OnRequest, onresponse=OnResponse,
- timeout=Timeout, until=until(Timeout)}, 0).
+ onresponse=OnResponse, timeout=Timeout, until=until(Timeout)}, 0).
-spec until(timeout()) -> non_neg_integer() | infinity.
until(infinity) ->
@@ -410,26 +406,12 @@ request(Buffer, State=#state{socket=Socket, transport=Transport,
Req = cowboy_req:new(Socket, Transport, Peer, Method, Path,
Query, Version, Headers, Host, Port, Buffer,
ReqKeepalive < MaxKeepalive, Compress, OnResponse),
- onrequest(Req, State);
+ execute(Req, State);
{error, _} ->
%% Couldn't read the peer address; connection is gone.
terminate(State)
end.
-%% Call the global onrequest callback. The callback can send a reply,
-%% in which case we consider the request handled and move on to the next
-%% one. Note that since we haven't dispatched yet, we don't know the
-%% handler, host_info, path_info or bindings yet.
--spec onrequest(cowboy_req:req(), #state{}) -> ok.
-onrequest(Req, State=#state{onrequest=undefined}) ->
- execute(Req, State);
-onrequest(Req, State=#state{onrequest=OnRequest}) ->
- Req2 = OnRequest(Req),
- case cowboy_req:get(resp_state, Req2) of
- waiting -> execute(Req2, State);
- _ -> next_request(Req2, State, ok)
- end.
-
-spec execute(cowboy_req:req(), #state{}) -> ok.
execute(Req, State=#state{middlewares=Middlewares, env=Env}) ->
execute(Req, State, Env, Middlewares).
diff --git a/src/cowboy_spdy.erl b/src/cowboy_spdy.erl
index 8da9613..5b89c48 100644
--- a/src/cowboy_spdy.erl
+++ b/src/cowboy_spdy.erl
@@ -24,7 +24,7 @@
-export([system_code_change/4]).
%% Internal request process.
--export([request_init/11]).
+-export([request_init/10]).
-export([resume/5]).
-export([reply/4]).
-export([stream_reply/3]).
@@ -59,7 +59,6 @@
buffer = <<>> :: binary(),
middlewares,
env,
- onrequest,
onresponse,
peer,
zdef,
@@ -70,7 +69,6 @@
-type opts() :: [{env, cowboy_middleware:env()}
| {middlewares, [module()]}
- | {onrequest, cowboy:onrequest_fun()}
| {onresponse, cowboy:onresponse_fun()}].
-export_type([opts/0]).
@@ -97,13 +95,12 @@ init(Parent, Ref, Socket, Transport, Opts) ->
{ok, Peer} = Transport:peername(Socket),
Middlewares = get_value(middlewares, Opts, [cowboy_router, cowboy_handler]),
Env = [{listener, Ref}|get_value(env, Opts, [])],
- OnRequest = get_value(onrequest, Opts, undefined),
OnResponse = get_value(onresponse, Opts, undefined),
Zdef = cow_spdy:deflate_init(),
Zinf = cow_spdy:inflate_init(),
ok = ranch:accept_ack(Ref),
loop(#state{parent=Parent, socket=Socket, transport=Transport,
- middlewares=Middlewares, env=Env, onrequest=OnRequest,
+ middlewares=Middlewares, env=Env,
onresponse=OnResponse, peer=Peer, zdef=Zdef, zinf=Zinf}).
loop(State=#state{parent=Parent, socket=Socket, transport=Transport,
@@ -257,11 +254,11 @@ handle_frame(State, {syn_stream, StreamID, AssocToStreamID,
%% Erlang does not allow us to control the priority of processes
%% so we ignore that value entirely.
handle_frame(State=#state{middlewares=Middlewares, env=Env,
- onrequest=OnRequest, onresponse=OnResponse, peer=Peer},
+ onresponse=OnResponse, peer=Peer},
{syn_stream, StreamID, _, IsFin, _, _,
Method, _, Host, Path, Version, Headers}) ->
Pid = spawn_link(?MODULE, request_init, [
- {self(), StreamID}, Peer, OnRequest, OnResponse,
+ {self(), StreamID}, Peer, OnResponse,
Env, Middlewares, Method, Host, Path, Version, Headers
]),
new_child(State, StreamID, Pid, IsFin);
@@ -385,11 +382,10 @@ delete_child(Pid, State=#state{children=Children}) ->
%% Request process.
-spec request_init(socket(), {inet:ip_address(), inet:port_number()},
- cowboy:onrequest_fun(), cowboy:onresponse_fun(),
- cowboy_middleware:env(), [module()],
+ cowboy:onresponse_fun(), cowboy_middleware:env(), [module()],
binary(), binary(), binary(), binary(), [{binary(), binary()}])
-> ok.
-request_init(FakeSocket, Peer, OnRequest, OnResponse,
+request_init(FakeSocket, Peer, OnResponse,
Env, Middlewares, Method, Host, Path, Version, Headers) ->
{Host2, Port} = cow_http:parse_fullhost(Host),
{Path2, Qs} = cow_http:parse_fullpath(Path),
@@ -397,16 +393,7 @@ request_init(FakeSocket, Peer, OnRequest, OnResponse,
Req = cowboy_req:new(FakeSocket, ?MODULE, Peer,
Method, Path2, Qs, Version2, Headers,
Host2, Port, <<>>, true, false, OnResponse),
- case OnRequest of
- undefined ->
- execute(Req, Env, Middlewares);
- _ ->
- Req2 = OnRequest(Req),
- case cowboy_req:get(resp_state, Req2) of
- waiting -> execute(Req2, Env, Middlewares);
- _ -> ok
- end
- end.
+ execute(Req, Env, Middlewares).
-spec execute(cowboy_req:req(), cowboy_middleware:env(), [module()])
-> ok.