Packages
erlcloud
3.3.6
3.8.3
3.8.2
3.8.1
3.7.6
3.7.4
3.7.3
3.7.2
3.7.1
3.7.0
3.6.8
3.6.7
3.6.5
3.6.4
3.6.3
3.6.2
3.6.1
3.6.0
3.5.16
3.5.15
3.5.14
3.5.13
3.5.12
3.5.11
3.5.10
3.5.9
3.5.8
3.5.7
3.5.6
3.5.5
3.5.4
3.5.3
3.5.2
3.5.1
3.5.0
3.4.5
3.4.3
3.4.1
3.4.0
3.3.9
3.3.8
3.3.7
3.3.6
3.3.5
3.3.4
3.3.3
3.3.2
3.3.1
3.3.0
3.2.18
3.2.17
3.2.16
3.2.15
3.2.14
3.2.13
3.2.12
3.2.11
3.2.10
3.2.7
3.2.6
3.2.5
3.2.4
3.2.3
3.2.2
3.2.1
3.2.0
3.1.17
3.1.16
3.1.14
3.1.13
3.1.12
3.1.11
3.1.9
3.1.8
3.1.7
3.1.6
3.1.5
3.1.4
3.1.3
3.1.2
3.1.1
3.1.0
3.0.5
3.0.4
3.0.3
3.0.2
3.0.1
2.2.16
2.2.15
2.2.14
2.2.13
2.2.12
2.2.11
2.2.10
2.2.9
2.2.8
2.2.7
2.2.6
2.2.5
2.2.4
2.2.2
2.2.1
2.2.0
2.1.0
2.0.5
2.0.4
2.0.3
2.0.0
0.13.10
0.13.9
0.13.8
0.13.6
0.13.5
0.13.4
0.13.3
0.13.2
0.13.0
0.12.0
0.11.0
0.9.2
0.9.2-rc.1
0.9.1
0.9.0
AWS APIs library for Erlang
Current section
Files
Jump to
Current section
Files
src/erlcloud_http.erl
-module(erlcloud_http).
-export([make_query_string/1, make_query_string/2, value_to_string/1, url_encode/1, url_encode_loose/1]).
encode_query_term(Key, [], no_assignment) ->
[Key];
encode_query_term(Key, [], empty_assignment) ->
[Key, "="];
encode_query_term(Key, Value, _) ->
[Key, "=", url_encode(value_to_string(Value))].
%% encode an empty value query string differently based on the
%% argument provided, this is based on the fact that S3 and SQS
%% sign url differently, S3 requires that empty arguments have no
%% '=' (/?acl) while SQS requires it (/?QueuePrefix=)
%% default behaviour is adding '='
make_query_string(Params) ->
make_query_string(Params, empty_assignment).
make_query_string(Params, EmptyQueryOpt) ->
string:join([encode_query_term(Key, Value, EmptyQueryOpt) || {Key, Value} <-
Params, Value =/= none, Value =/= undefined], "&").
value_to_string(Integer) when is_integer(Integer) -> integer_to_list(Integer);
value_to_string(Atom) when is_atom(Atom) -> atom_to_list(Atom);
value_to_string(Binary) when is_binary(Binary) -> Binary;
value_to_string(String) when is_list(String) -> unicode:characters_to_binary(String).
url_encode(Binary) when is_binary(Binary) ->
url_encode(unicode:characters_to_list(Binary));
url_encode(String) ->
url_encode(String, []).
url_encode([], Accum) ->
lists:reverse(Accum);
url_encode([Char|String], Accum)
when Char >= $A, Char =< $Z;
Char >= $a, Char =< $z;
Char >= $0, Char =< $9;
Char =:= $-; Char =:= $_;
Char =:= $.; Char =:= $~ ->
url_encode(String, [Char|Accum]);
url_encode([Char|String], Accum) ->
url_encode(String, utf8_encode_char(Char) ++ Accum).
url_encode_loose(Binary) when is_binary(Binary) ->
url_encode_loose(binary_to_list(Binary));
url_encode_loose(String) ->
url_encode_loose(String, []).
url_encode_loose([], Accum) ->
lists:reverse(Accum);
url_encode_loose([Char|String], Accum)
when Char >= $A, Char =< $Z;
Char >= $a, Char =< $z;
Char >= $0, Char =< $9;
Char =:= $-; Char =:= $_;
Char =:= $.; Char =:= $~;
Char =:= $/ ->
url_encode_loose(String, [Char|Accum]);
url_encode_loose([Char|String], Accum)
when Char >=0, Char =< 255 ->
url_encode_loose(String, [hex_char(Char rem 16), hex_char(Char div 16), $% | Accum]).
utf8_encode_char(Char) when Char > 16#FFFF, Char =< 16#10FFFF ->
encode_char(Char band 16#3F + 16#80)
++ encode_char((16#3F band (Char bsr 6)) + 16#80)
++ encode_char((16#3F band (Char bsr 12)) + 16#80)
++ encode_char((Char bsr 18) + 16#F0);
utf8_encode_char(Char) when Char > 16#7FF, Char =< 16#FFFF ->
encode_char(Char band 16#3F + 16#80)
++ encode_char((16#3F band (Char bsr 6)) + 16#80)
++ encode_char((Char bsr 12) + 16#E0);
utf8_encode_char(Char) when Char > 16#7F, Char =< 16#7FF ->
encode_char(Char band 16#3F + 16#80)
++ encode_char((Char bsr 6) + 16#C0);
utf8_encode_char(Char) when Char =< 16#7F ->
encode_char(Char).
encode_char(Char) ->
[hex_char(Char rem 16), hex_char(Char div 16), $%].
hex_char(C) when C < 10 -> $0 + C;
hex_char(C) when C < 16 -> $A + C - 10.