Skip to content

Commit

Permalink
remove removal schedule of http_uri and change its implementation to …
Browse files Browse the repository at this point in the history
…uri_string
  • Loading branch information
Whaileee committed Mar 11, 2024
1 parent ecbc0be commit 4cb39aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 56 deletions.
58 changes: 4 additions & 54 deletions lib/inets/src/http_lib/http_uri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,58 +39,8 @@
%%%=========================================================================
%%% API
%%%=========================================================================
reserved() ->
sets:from_list([$;, $:, $@, $&, $=, $+, $,, $/, $?,
$#, $[, $], $<, $>, $\", ${, $}, $|, %"
$\\, $', $^, $%, $ ]).
encode(URI) ->
uri_string:quote(URI).

encode(URI) when is_list(URI) ->
Reserved = reserved(),
lists:append([uri_encode(Char, Reserved) || Char <- URI]);
encode(URI) when is_binary(URI) ->
Reserved = reserved(),
<< <<(uri_encode_binary(Char, Reserved))/binary>> || <<Char>> <= URI >>.

decode(String) when is_list(String) ->
do_decode(String);
decode(String) when is_binary(String) ->
do_decode_binary(String).

do_decode([$%,Hex1,Hex2|Rest]) ->
[hex2dec(Hex1)*16+hex2dec(Hex2)|do_decode(Rest)];
do_decode([First|Rest]) ->
[First|do_decode(Rest)];
do_decode([]) ->
[].

do_decode_binary(<<$%, Hex:2/binary, Rest/bits>>) ->
<<(binary_to_integer(Hex, 16)), (do_decode_binary(Rest))/binary>>;
do_decode_binary(<<First:1/binary, Rest/bits>>) ->
<<First/binary, (do_decode_binary(Rest))/binary>>;
do_decode_binary(<<>>) ->
<<>>.

%%%========================================================================
%%% Internal functions
%%%========================================================================
%% In this version of the function, we no longer need
%% the Scheme argument, but just in case...
uri_encode(Char, Reserved) ->
case sets:is_element(Char, Reserved) of
true ->
[ $% | http_util:integer_to_hexlist(Char)];
false ->
[Char]
end.

uri_encode_binary(Char, Reserved) ->
case sets:is_element(Char, Reserved) of
true ->
<< $%, (integer_to_binary(Char, 16))/binary >>;
false ->
<<Char>>
end.

hex2dec(X) when (X>=$0) andalso (X=<$9) -> X-$0;
hex2dec(X) when (X>=$A) andalso (X=<$F) -> X-$A+10;
hex2dec(X) when (X>=$a) andalso (X=<$f) -> X-$a+10.
decode(URI) ->
uri_string:unquote(URI).
4 changes: 2 additions & 2 deletions system/doc/general_info/DEPRECATIONS
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ ssl:cipher_suites/0 since=21 remove=24

http_uri:parse/1 since=23 remove=25
http_uri:parse/2 since=23 remove=25
http_uri:encode/1 since=23 remove=27
http_uri:decode/1 since=23 remove=27
http_uri:encode/1 since=23
http_uri:decode/1 since=23
http_uri:scheme_defaults/0 since=23 remove=25
httpd:parse_query/1 since=23
pg2:_/_ since=23 remove=24
Expand Down

0 comments on commit 4cb39aa

Please sign in to comment.