Browse Source

Move the dispatcher related types into cowboy_dispatcher.

Loïc Hoguin 14 years ago
parent
commit
2beb5c8206
5 changed files with 17 additions and 14 deletions
  1. 3 3
      include/http.hrl
  2. 0 8
      include/types.hrl
  3. 9 0
      src/cowboy_dispatcher.erl
  4. 1 1
      src/cowboy_http_protocol.erl
  5. 4 2
      src/cowboy_http_req.erl

+ 3 - 3
include/http.hrl

@@ -46,13 +46,13 @@
 	method     = 'GET'     :: http_method(),
 	version    = {1, 1}    :: http_version(),
 	peer       = undefined :: undefined | {Address::inet:ip_address(), Port::port_number()},
-	host       = undefined :: undefined | path_tokens(),
+	host       = undefined :: undefined | cowboy_dispatcher:path_tokens(),
 	raw_host   = undefined :: undefined | string(),
-	path       = undefined :: undefined | '*' | path_tokens(),
+	path       = undefined :: undefined | '*' | cowboy_dispatcher:path_tokens(),
 	raw_path   = undefined :: undefined | string(),
 	qs_vals    = undefined :: undefined | list({Name::string(), Value::string() | true}),
 	raw_qs     = undefined :: undefined | string(),
-	bindings   = undefined :: undefined | bindings(),
+	bindings   = undefined :: undefined | cowboy_dispatcher:bindings(),
 	headers    = []        :: http_headers(),
 %%	cookies    = undefined :: undefined | http_cookies() %% @todo
 

+ 0 - 8
include/types.hrl

@@ -17,11 +17,3 @@
 
 -type posix() :: atom().
 -type port_number() :: 0..65535.
-
--type bindings() :: list({Key::atom(), Value::string()}).
--type path_tokens() :: list(nonempty_string()).
--type match_rule() :: '_' | '*' | list(string() | '_' | atom()).
-
--type dispatch_rule() :: {Host::match_rule(), list({Path::match_rule(),
-	Handler::module(), Opts::term()})}.
--type dispatch_rules() :: list(dispatch_rule()).

+ 9 - 0
src/cowboy_dispatcher.erl

@@ -15,6 +15,15 @@
 -module(cowboy_dispatcher).
 -export([split_host/1, split_path/1, match/3]). %% API.
 
+-type bindings() :: list({Key::atom(), Value::string()}).
+-type path_tokens() :: list(nonempty_string()).
+-type match_rule() :: '_' | '*' | list(string() | '_' | atom()).
+-type dispatch_rule() :: {Host::match_rule(), list({Path::match_rule(),
+	Handler::module(), Opts::term()})}.
+-type dispatch_rules() :: list(dispatch_rule()).
+
+-export_type([bindings/0, path_tokens/0, dispatch_rules/0]).
+
 -include("include/types.hrl").
 -include_lib("eunit/include/eunit.hrl").
 

+ 1 - 1
src/cowboy_http_protocol.erl

@@ -22,7 +22,7 @@
 -record(state, {
 	socket :: inet:socket(),
 	transport :: module(),
-	dispatch :: dispatch_rules(),
+	dispatch :: cowboy_dispatcher:dispatch_rules(),
 	handler :: {Handler::module(), Opts::term()},
 	req_empty_lines = 0 :: integer(),
 	max_empty_lines :: integer(),

+ 4 - 2
src/cowboy_http_req.erl

@@ -55,7 +55,8 @@ peer(Req=#http_req{socket=Socket, transport=Transport, peer=undefined}) ->
 peer(Req) ->
 	{Req#http_req.peer, Req}.
 
--spec host(Req::#http_req{}) -> {Host::path_tokens(), Req::#http_req{}}.
+-spec host(Req::#http_req{})
+	-> {Host::cowboy_dispatcher:path_tokens(), Req::#http_req{}}.
 host(Req) ->
 	{Req#http_req.host, Req}.
 
@@ -63,7 +64,8 @@ host(Req) ->
 raw_host(Req) ->
 	{Req#http_req.raw_host, Req}.
 
--spec path(Req::#http_req{}) -> {Path::path_tokens(), Req::#http_req{}}.
+-spec path(Req::#http_req{})
+	-> {Path::cowboy_dispatcher:path_tokens(), Req::#http_req{}}.
 path(Req) ->
 	{Req#http_req.path, Req}.