Browse Source

Add types for onrequest and onresponse funs

Loïc Hoguin 12 years ago
parent
commit
c2be7c1920
2 changed files with 10 additions and 5 deletions
  1. 9 3
      src/cowboy_protocol.erl
  2. 1 2
      src/cowboy_req.erl

+ 9 - 3
src/cowboy_protocol.erl

@@ -46,15 +46,21 @@
 -include_lib("eunit/include/eunit.hrl").
 -include_lib("eunit/include/eunit.hrl").
 -endif.
 -endif.
 
 
+-type onrequest_fun() :: fun((Req) -> Req).
+-type onresponse_fun() ::
+	fun((cowboy_http:status(), cowboy_http:headers(), Req) -> Req).
+
+-export_type([onrequest_fun/0]).
+-export_type([onresponse_fun/0]).
+
 -record(state, {
 -record(state, {
 	listener :: pid(),
 	listener :: pid(),
 	socket :: inet:socket(),
 	socket :: inet:socket(),
 	transport :: module(),
 	transport :: module(),
 	dispatch :: cowboy_dispatcher:dispatch_rules(),
 	dispatch :: cowboy_dispatcher:dispatch_rules(),
 	handler :: {module(), any()},
 	handler :: {module(), any()},
-	onrequest :: undefined | fun((cowboy_req:req()) -> cowboy_req:req()),
-	onresponse = undefined :: undefined | fun((cowboy_http:status(),
-		cowboy_http:headers(), cowboy_req:req()) -> cowboy_req:req()),
+	onrequest :: undefined | onrequest_fun(),
+	onresponse = undefined :: undefined | onresponse_fun(),
 	urldecode :: {fun((binary(), T) -> binary()), T},
 	urldecode :: {fun((binary(), T) -> binary()), T},
 	req_empty_lines = 0 :: integer(),
 	req_empty_lines = 0 :: integer(),
 	max_empty_lines :: integer(),
 	max_empty_lines :: integer(),

+ 1 - 2
src/cowboy_req.erl

@@ -158,8 +158,7 @@
 		| {non_neg_integer(), fun(() -> {sent, non_neg_integer()})},
 		| {non_neg_integer(), fun(() -> {sent, non_neg_integer()})},
 
 
 	%% Functions.
 	%% Functions.
-	onresponse = undefined :: undefined | fun((cowboy_http:status(),
-		cowboy_http:headers(), Req) -> Req),
+	onresponse = undefined :: undefined | cowboy_protocol:onresponse_fun(),
 	urldecode :: {fun((binary(), T) -> binary()), T}
 	urldecode :: {fun((binary(), T) -> binary()), T}
 }).
 }).