diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2018-03-17 13:09:26 +0100 |
---|---|---|
committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2018-03-27 19:18:32 +0200 |
commit | 8d8e9d54c859625277c7de977b361165c09b06b1 (patch) | |
tree | 6d8f0051b3598d21edd3c6d725e55c16f8e36855 /core | |
parent | b76ee30917c63211ac9e94a21bebbddf518d169f (diff) |
Enhance HTTPClient.query_string_from_dict()
Diffstat (limited to 'core')
-rw-r--r-- | core/io/http_client.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 6e4931f34b..c787b7ec4c 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -618,7 +618,27 @@ String HTTPClient::query_string_from_dict(const Dictionary &p_dict) { String query = ""; Array keys = p_dict.keys(); for (int i = 0; i < keys.size(); ++i) { - query += "&" + String(keys[i]).percent_encode() + "=" + String(p_dict[keys[i]]).percent_encode(); + String encoded_key = String(keys[i]).percent_encode(); + Variant value = p_dict[keys[i]]; + switch (value.get_type()) { + case Variant::ARRAY: { + // Repeat the key with every values + Array values = value; + for (int j = 0; j < values.size(); ++j) { + query += "&" + encoded_key + "=" + String(values[j]).percent_encode(); + } + break; + } + case Variant::NIL: { + // Add the key with no value + query += "&" + encoded_key; + break; + } + default: { + // Add the key-value pair + query += "&" + encoded_key + "=" + String(value).percent_encode(); + } + } } query.erase(0, 1); return query; |