diff options
author | Loïc Hoguin <[email protected]> | 2011-03-19 18:53:59 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2011-03-19 18:53:59 +0100 |
commit | a4f8bb65739b8a3b102c244a5ef7e5aa6a9f38e4 (patch) | |
tree | b1684461aa7dab26a70ec5335c1f24b73688613f /src/cowboy_dispatcher.erl | |
parent | 2c52a30b0a209cfb0814a42b814271b168ddb2e2 (diff) | |
download | cowboy-a4f8bb65739b8a3b102c244a5ef7e5aa6a9f38e4.tar.gz cowboy-a4f8bb65739b8a3b102c244a5ef7e5aa6a9f38e4.tar.bz2 cowboy-a4f8bb65739b8a3b102c244a5ef7e5aa6a9f38e4.zip |
Add support for the '*' path.
Mostly used by the following request: OPTIONS * HTTP/1.1
Diffstat (limited to 'src/cowboy_dispatcher.erl')
-rw-r--r-- | src/cowboy_dispatcher.erl | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/cowboy_dispatcher.erl b/src/cowboy_dispatcher.erl index 755a398..d66caf0 100644 --- a/src/cowboy_dispatcher.erl +++ b/src/cowboy_dispatcher.erl @@ -25,6 +25,8 @@ split_host(Host) -> string:tokens(Host, "."). -spec split_path(Path::string()) -> {Tokens::path_tokens(), Qs::string()}. +split_path('*') -> + {'*', []}; split_path(Path) -> case string:chr(Path, $?) of 0 -> @@ -57,6 +59,8 @@ match_path(_Path, [], _HostBinds) -> {error, notfound, path}; match_path(_Path, [{'_', Handler, Opts}|_Tail], HostBinds) -> {ok, Handler, Opts, HostBinds}; +match_path('*', [{'*', Handler, Opts}|_Tail], HostBinds) -> + {ok, Handler, Opts, HostBinds}; match_path(Path, [{PathMatch, Handler, Opts}|Tail], HostBinds) -> case try_match(path, Path, PathMatch) of false -> @@ -120,7 +124,6 @@ split_path_test_() -> Tests = [ {"?", [], []}, {"???", [], "??"}, - {"*", ["*"], []}, {"/", [], []}, {"/users", ["users"], []}, {"/users?", ["users"], []}, @@ -128,7 +131,8 @@ split_path_test_() -> {"/users/42/friends?a=b&c=d&e=notsure?whatever", ["users", "42", "friends"], "a=b&c=d&e=notsure?whatever"} ], - [{P, fun() -> {R, Qs} = split_path(P) end} || {P, R, Qs} <- Tests]. + [{"atom '*'", fun() -> {'*', []} = split_path('*') end}] + ++ [{P, fun() -> {R, Qs} = split_path(P) end} || {P, R, Qs} <- Tests]. match_test_() -> Dispatch = [ |