aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-09-23 21:25:54 +0200
committerLoïc Hoguin <[email protected]>2012-09-23 21:25:54 +0200
commit332c274d87df36e413ea698b753e0ddaa55dd796 (patch)
tree7ef6e2ea55e3fadcd0bedfaa0075e138adedf3e9 /src
parentff3c5c7f45cdbd641098076a482ce8b852bbc88c (diff)
downloadcowboy-332c274d87df36e413ea698b753e0ddaa55dd796.tar.gz
cowboy-332c274d87df36e413ea698b753e0ddaa55dd796.tar.bz2
cowboy-332c274d87df36e413ea698b753e0ddaa55dd796.zip
Use binary:match/2 instead of binary:split/2 in cowboy_http
Also fix a bug introduced in a previous commit.
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http.erl23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index 9c38fae..a936e2c 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -95,17 +95,22 @@ request_line(Data) ->
%% We just want to extract the path/qs and skip everything else.
%% We do not really parse the URI, nor do we need to.
uri_to_abspath(Data, Fun) ->
- case binary:split(Data, <<" ">>) of
- [_] -> %% We require the HTTP version.
+ case binary:match(Data, <<" ">>) of
+ nomatch -> %% We require the HTTP version.
{error, badarg};
- [URI, Rest] ->
- case binary:split(URI, <<"://">>) of
- [_] -> %% Already is a path or "*".
+ {Pos1, _} ->
+ << URI:Pos1/binary, _:8, Rest/bits >> = Data,
+ case binary:match(URI, <<"://">>) of
+ nomatch -> %% Already is a path or "*".
Fun(Rest, URI);
- [_, NoScheme] ->
- case binary:split(NoScheme, <<"/">>) of
- [_] -> <<"/">>;
- [_, NoHost] -> Fun(Rest, << "/", NoHost/binary >>)
+ {Pos2, _} ->
+ << _:Pos2/binary, _:24, NoScheme/bits >> = Rest,
+ case binary:match(NoScheme, <<"/">>) of
+ nomatch ->
+ Fun(Rest, <<"/">>);
+ {Pos3, _} ->
+ << _:Pos3/binary, _:8, NoHost/bits >> = NoScheme,
+ Fun(Rest, << "/", NoHost/binary >>)
end
end
end.