0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Rename the type cowboy_dispatcher:path_tokens/0 to :tokens/0

This commit is contained in:
Loïc Hoguin 2011-10-01 02:32:20 +02:00
parent 6572d4d374
commit ce26d7090b
3 changed files with 24 additions and 24 deletions

View file

@ -47,12 +47,12 @@
method = 'GET' :: http_method(),
version = {1, 1} :: http_version(),
peer = undefined :: undefined | {inet:ip_address(), inet:ip_port()},
host = undefined :: undefined | cowboy_dispatcher:path_tokens(),
host_info = undefined :: undefined | cowboy_dispatcher:path_tokens(),
host = undefined :: undefined | cowboy_dispatcher:tokens(),
host_info = undefined :: undefined | cowboy_dispatcher:tokens(),
raw_host = undefined :: undefined | binary(),
port = undefined :: undefined | inet:ip_port(),
path = undefined :: undefined | '*' | cowboy_dispatcher:path_tokens(),
path_info = undefined :: undefined | cowboy_dispatcher:path_tokens(),
path = undefined :: undefined | '*' | cowboy_dispatcher:tokens(),
path_info = undefined :: undefined | cowboy_dispatcher:tokens(),
raw_path = undefined :: undefined | binary(),
qs_vals = undefined :: undefined | list({binary(), binary() | true}),
raw_qs = undefined :: undefined | binary(),

View file

@ -19,13 +19,13 @@
-export([split_host/1, split_path/1, match/3]). %% API.
-type bindings() :: list({atom(), binary()}).
-type path_tokens() :: list(binary()).
-type tokens() :: list(binary()).
-type match_rule() :: '_' | '*' | list(binary() | '_' | '...' | atom()).
-type dispatch_path() :: list({match_rule(), module(), any()}).
-type dispatch_rule() :: {Host::match_rule(), Path::dispatch_path()}.
-type dispatch_rules() :: list(dispatch_rule()).
-export_type([bindings/0, path_tokens/0, dispatch_rules/0]).
-export_type([bindings/0, tokens/0, dispatch_rules/0]).
-include_lib("eunit/include/eunit.hrl").
@ -33,7 +33,7 @@
%% @doc Split a hostname into a list of tokens.
-spec split_host(binary())
-> {path_tokens(), binary(), undefined | inet:ip_port()}.
-> {tokens(), binary(), undefined | inet:ip_port()}.
split_host(<<>>) ->
{[], <<>>, undefined};
split_host(Host) ->
@ -50,7 +50,7 @@ split_host(Host) ->
%% Following RFC2396, this function may return path segments containing any
%% character, including <em>/</em> if, and only if, a <em>/</em> was escaped
%% and part of a path segment.
-spec split_path(binary()) -> {path_tokens(), binary(), binary()}.
-spec split_path(binary()) -> {tokens(), binary(), binary()}.
split_path(Path) ->
case binary:split(Path, <<"?">>) of
[Path] -> {do_split_path(Path, <<"/">>), Path, <<>>};
@ -58,7 +58,7 @@ split_path(Path) ->
[Path2, Qs] -> {do_split_path(Path2, <<"/">>), Path2, Qs}
end.
-spec do_split_path(binary(), <<_:8>>) -> path_tokens().
-spec do_split_path(binary(), <<_:8>>) -> tokens().
do_split_path(RawPath, Separator) ->
EncodedPath = case binary:split(RawPath, Separator, [global, trim]) of
[<<>>|Path] -> Path;
@ -93,10 +93,10 @@ do_split_path(RawPath, Separator) ->
%% options found in the dispatch list, a key-value list of bindings and
%% the tokens that were matched by the <em>'...'</em> atom for both the
%% hostname and path.
-spec match(Host::path_tokens(), Path::path_tokens(), dispatch_rules())
-spec match(Host::tokens(), Path::tokens(), dispatch_rules())
-> {ok, module(), any(), bindings(),
HostInfo::undefined | path_tokens(),
PathInfo::undefined | path_tokens()}
HostInfo::undefined | tokens(),
PathInfo::undefined | tokens()}
| {error, notfound, host} | {error, notfound, path}.
match(_Host, _Path, []) ->
{error, notfound, host};
@ -112,11 +112,11 @@ match(Host, Path, [{HostMatch, PathMatchs}|Tail]) ->
match_path(Path, PathMatchs, HostBinds, lists:reverse(HostInfo))
end.
-spec match_path(path_tokens(), dispatch_path(), bindings(),
HostInfo::undefined | path_tokens())
-spec match_path(tokens(), dispatch_path(), bindings(),
HostInfo::undefined | tokens())
-> {ok, module(), any(), bindings(),
HostInfo::undefined | path_tokens(),
PathInfo::undefined | path_tokens()}
HostInfo::undefined | tokens(),
PathInfo::undefined | tokens()}
| {error, notfound, path}.
match_path(_Path, [], _HostBinds, _HostInfo) ->
{error, notfound, path};
@ -134,15 +134,15 @@ match_path(Path, [{PathMatch, Handler, Opts}|Tail], HostBinds, HostInfo) ->
%% Internal.
-spec try_match(host | path, path_tokens(), match_rule())
-> {true, bindings(), undefined | path_tokens()} | false.
-spec try_match(host | path, tokens(), match_rule())
-> {true, bindings(), undefined | tokens()} | false.
try_match(host, List, Match) ->
list_match(lists:reverse(List), lists:reverse(Match), []);
try_match(path, List, Match) ->
list_match(List, Match, []).
-spec list_match(path_tokens(), match_rule(), bindings())
-> {true, bindings(), undefined | path_tokens()} | false.
-spec list_match(tokens(), match_rule(), bindings())
-> {true, bindings(), undefined | tokens()} | false.
%% Atom '...' matches any trailing path, stop right now.
list_match(List, ['...'], Binds) ->
{true, Binds, List};

View file

@ -67,14 +67,14 @@ peer(Req) ->
{Req#http_req.peer, Req}.
%% @doc Return the tokens for the hostname requested.
-spec host(#http_req{}) -> {cowboy_dispatcher:path_tokens(), #http_req{}}.
-spec host(#http_req{}) -> {cowboy_dispatcher:tokens(), #http_req{}}.
host(Req) ->
{Req#http_req.host, Req}.
%% @doc Return the extra host information obtained from partially matching
%% the hostname using <em>'...'</em>.
-spec host_info(#http_req{})
-> {cowboy_dispatcher:path_tokens() | undefined, #http_req{}}.
-> {cowboy_dispatcher:tokens() | undefined, #http_req{}}.
host_info(Req) ->
{Req#http_req.host_info, Req}.
@ -93,14 +93,14 @@ port(Req) ->
%% Following RFC2396, this function may return path segments containing any
%% character, including <em>/</em> if, and only if, a <em>/</em> was escaped
%% and part of a path segment in the path requested.
-spec path(#http_req{}) -> {cowboy_dispatcher:path_tokens(), #http_req{}}.
-spec path(#http_req{}) -> {cowboy_dispatcher:tokens(), #http_req{}}.
path(Req) ->
{Req#http_req.path, Req}.
%% @doc Return the extra path information obtained from partially matching
%% the patch using <em>'...'</em>.
-spec path_info(#http_req{})
-> {cowboy_dispatcher:path_tokens() | undefined, #http_req{}}.
-> {cowboy_dispatcher:tokens() | undefined, #http_req{}}.
path_info(Req) ->
{Req#http_req.path_info, Req}.