mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Use binary:match/2 instead of binary:split/2 in cowboy_http
Also fix a bug introduced in a previous commit.
This commit is contained in:
parent
ff3c5c7f45
commit
332c274d87
1 changed files with 14 additions and 9 deletions
|
@ -95,17 +95,22 @@ request_line(Data) ->
|
||||||
%% We just want to extract the path/qs and skip everything else.
|
%% We just want to extract the path/qs and skip everything else.
|
||||||
%% We do not really parse the URI, nor do we need to.
|
%% We do not really parse the URI, nor do we need to.
|
||||||
uri_to_abspath(Data, Fun) ->
|
uri_to_abspath(Data, Fun) ->
|
||||||
case binary:split(Data, <<" ">>) of
|
case binary:match(Data, <<" ">>) of
|
||||||
[_] -> %% We require the HTTP version.
|
nomatch -> %% We require the HTTP version.
|
||||||
{error, badarg};
|
{error, badarg};
|
||||||
[URI, Rest] ->
|
{Pos1, _} ->
|
||||||
case binary:split(URI, <<"://">>) of
|
<< URI:Pos1/binary, _:8, Rest/bits >> = Data,
|
||||||
[_] -> %% Already is a path or "*".
|
case binary:match(URI, <<"://">>) of
|
||||||
|
nomatch -> %% Already is a path or "*".
|
||||||
Fun(Rest, URI);
|
Fun(Rest, URI);
|
||||||
[_, NoScheme] ->
|
{Pos2, _} ->
|
||||||
case binary:split(NoScheme, <<"/">>) of
|
<< _:Pos2/binary, _:24, NoScheme/bits >> = Rest,
|
||||||
[_] -> <<"/">>;
|
case binary:match(NoScheme, <<"/">>) of
|
||||||
[_, NoHost] -> Fun(Rest, << "/", NoHost/binary >>)
|
nomatch ->
|
||||||
|
Fun(Rest, <<"/">>);
|
||||||
|
{Pos3, _} ->
|
||||||
|
<< _:Pos3/binary, _:8, NoHost/bits >> = NoScheme,
|
||||||
|
Fun(Rest, << "/", NoHost/binary >>)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue