From ce26d7090b178c84d1dde1be3f4dc892138b8667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sat, 1 Oct 2011 02:32:20 +0200 Subject: Rename the type cowboy_dispatcher:path_tokens/0 to :tokens/0 --- include/http.hrl | 8 ++++---- src/cowboy_dispatcher.erl | 32 ++++++++++++++++---------------- src/cowboy_http_req.erl | 8 ++++---- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/http.hrl b/include/http.hrl index 7e0380d..2364daa 100644 --- a/include/http.hrl +++ b/include/http.hrl @@ -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(), diff --git a/src/cowboy_dispatcher.erl b/src/cowboy_dispatcher.erl index bb87fc9..67ea34b 100644 --- a/src/cowboy_dispatcher.erl +++ b/src/cowboy_dispatcher.erl @@ -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 / if, and only if, a / 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 '...' 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}; diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl index ead9831..1ea656f 100644 --- a/src/cowboy_http_req.erl +++ b/src/cowboy_http_req.erl @@ -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 '...'. -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 / if, and only if, a / 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 '...'. -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}. -- cgit v1.2.3