0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Use binary_to_integer instead of to list and back

This commit is contained in:
Loïc Hoguin 2016-08-10 17:50:28 +02:00
parent 9966df9ad4
commit 83aa3f1b9c
4 changed files with 4 additions and 4 deletions

View file

@ -52,7 +52,7 @@ apply_constraint(Value, F) when is_function(F) ->
%% Constraint functions. %% Constraint functions.
int(Value) when is_binary(Value) -> int(Value) when is_binary(Value) ->
try {true, list_to_integer(binary_to_list(Value))} try {true, binary_to_integer(Value)}
catch _:_ -> false catch _:_ -> false
end. end.

View file

@ -578,7 +578,7 @@ parse_host(<< $[, Rest/bits >>, false, <<>>) ->
parse_host(<<>>, false, Acc) -> parse_host(<<>>, false, Acc) ->
{Acc, undefined}; {Acc, undefined};
parse_host(<< $:, Rest/bits >>, false, Acc) -> parse_host(<< $:, Rest/bits >>, false, Acc) ->
{Acc, list_to_integer(binary_to_list(Rest))}; {Acc, binary_to_integer(Rest)};
parse_host(<< $], Rest/bits >>, true, Acc) -> parse_host(<< $], Rest/bits >>, true, Acc) ->
parse_host(Rest, false, << Acc/binary, $] >>); parse_host(Rest, false, << Acc/binary, $] >>);
parse_host(<< C, Rest/bits >>, E, Acc) -> parse_host(<< C, Rest/bits >>, E, Acc) ->

View file

@ -91,7 +91,7 @@ websocket_upgrade(State, Req) ->
%% @todo Should probably send a 426 if the Upgrade header is missing. %% @todo Should probably send a 426 if the Upgrade header is missing.
[<<"websocket">>] = cowboy_req:parse_header(<<"upgrade">>, Req), [<<"websocket">>] = cowboy_req:parse_header(<<"upgrade">>, Req),
Version = cowboy_req:header(<<"sec-websocket-version">>, Req), Version = cowboy_req:header(<<"sec-websocket-version">>, Req),
IntVersion = list_to_integer(binary_to_list(Version)), IntVersion = binary_to_integer(Version),
true = (IntVersion =:= 7) orelse (IntVersion =:= 8) true = (IntVersion =:= 7) orelse (IntVersion =:= 8)
orelse (IntVersion =:= 13), orelse (IntVersion =:= 13),
Key = cowboy_req:header(<<"sec-websocket-key">>, Req), Key = cowboy_req:header(<<"sec-websocket-key">>, Req),

View file

@ -11,7 +11,7 @@ init(Req, Opts) ->
multipart(Req) -> multipart(Req) ->
case cowboy_req:read_part(Req) of case cowboy_req:read_part(Req) of
{ok, [{<<"content-length">>, BinLength}], Req2} -> {ok, [{<<"content-length">>, BinLength}], Req2} ->
Length = list_to_integer(binary_to_list(BinLength)), Length = binary_to_integer(BinLength),
{Length, Req3} = stream_body(Req2, 0), {Length, Req3} = stream_body(Req2, 0),
multipart(Req3); multipart(Req3);
{done, Req2} -> {done, Req2} ->