diff options
author | Loïc Hoguin <[email protected]> | 2012-11-27 12:02:31 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2012-11-27 12:02:31 +0100 |
commit | 8386e10dcc9a4136717d728bb8c0918dc57d9f93 (patch) | |
tree | b9150ca0c58a562265949da9840e8261de104f6c /src/cowboy_dispatcher.erl | |
parent | 9942beb58cb11c0f4ba4c98145b5cd1ff94985cf (diff) | |
parent | 0ce16b3cea25187914df89224c4e204b7715420e (diff) | |
download | cowboy-8386e10dcc9a4136717d728bb8c0918dc57d9f93.tar.gz cowboy-8386e10dcc9a4136717d728bb8c0918dc57d9f93.tar.bz2 cowboy-8386e10dcc9a4136717d728bb8c0918dc57d9f93.zip |
Merge branch '400_Bad_Request' of git://github.com/blinkov/cowboy
Diffstat (limited to 'src/cowboy_dispatcher.erl')
-rw-r--r-- | src/cowboy_dispatcher.erl | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/cowboy_dispatcher.erl b/src/cowboy_dispatcher.erl index 21874a9..fae18fc 100644 --- a/src/cowboy_dispatcher.erl +++ b/src/cowboy_dispatcher.erl @@ -68,7 +68,8 @@ -> {ok, module(), any(), bindings(), HostInfo::undefined | tokens(), PathInfo::undefined | tokens()} - | {error, notfound, host} | {error, notfound, path}. + | {error, notfound, host} | {error, notfound, path} + | {error, badrequest, path}. match([], _, _) -> {error, notfound, host}; match([{'_', PathMatchs}|_Tail], _, Path) -> @@ -92,7 +93,7 @@ match(Dispatch, Host, Path) -> -> {ok, module(), any(), bindings(), HostInfo::undefined | tokens(), PathInfo::undefined | tokens()} - | {error, notfound, path}. + | {error, notfound, path} | {error, badrequest, path}. match_path([], _, _, _) -> {error, notfound, path}; match_path([{'_', Handler, Opts}|_Tail], HostInfo, _, Bindings) -> @@ -107,6 +108,8 @@ match_path([{PathMatch, Handler, Opts}|Tail], HostInfo, Tokens, {true, PathBinds, PathInfo} -> {ok, Handler, Opts, Bindings ++ PathBinds, HostInfo, PathInfo} end; +match_path(_Dispatch, _HostInfo, badrequest, _Bindings) -> + {error, badrequest, path}; match_path(Dispatch, HostInfo, Path, Bindings) -> match_path(Dispatch, HostInfo, split_path(Path), Bindings). @@ -139,14 +142,19 @@ split_path(<< $/, Path/bits >>) -> split_path(Path, []). split_path(Path, Acc) -> - case binary:match(Path, <<"/">>) of - nomatch when Path =:= <<>> -> - lists:reverse([cowboy_http:urldecode(S) || S <- Acc]); - nomatch -> - lists:reverse([cowboy_http:urldecode(S) || S <- [Path|Acc]]); - {Pos, _} -> - << Segment:Pos/binary, _:8, Rest/bits >> = Path, - split_path(Rest, [Segment|Acc]) + try + case binary:match(Path, <<"/">>) of + nomatch when Path =:= <<>> -> + lists:reverse([cowboy_http:urldecode(S) || S <- Acc]); + nomatch -> + lists:reverse([cowboy_http:urldecode(S) || S <- [Path|Acc]]); + {Pos, _} -> + << Segment:Pos/binary, _:8, Rest/bits >> = Path, + split_path(Rest, [Segment|Acc]) + end + catch + error:badarg -> + badrequest end. -spec list_match(tokens(), match_rule(), bindings()) |