summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2015-11-19 10:44:13 -0300
committerJuan Linietsky <reduzio@gmail.com>2015-11-19 10:44:13 -0300
commitfd5ee87c24ed34baad0b541b1e100c6bf067fb92 (patch)
tree54a9e3ff765a721c360cdb65a767f15b75931029 /core
parentd3eb9e8c54d4a93b2bed90a5988f9814377d409f (diff)
parent83316bcc9ce6a07d11cc85cfe86bb7221c9a5d90 (diff)
Merge branch 'master' of https://github.com/okamstudio/godot
Conflicts: platform/windows/export/export.h
Diffstat (limited to 'core')
-rw-r--r--core/io/http_client.cpp15
-rw-r--r--core/io/http_client.h2
-rw-r--r--core/ustring.cpp42
-rw-r--r--core/ustring.h2
4 files changed, 59 insertions, 2 deletions
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 24012660d2..58092efd4b 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -579,7 +579,7 @@ Error HTTPClient::_get_http_data(uint8_t* p_buffer, int p_bytes,int &r_received)
void HTTPClient::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("connect:Error","host","port","use_ssl"),&HTTPClient::connect,DEFVAL(false),DEFVAL(true));
+ ObjectTypeDB::bind_method(_MD("connect:Error","host","port","use_ssl","verify_host"),&HTTPClient::connect,DEFVAL(false),DEFVAL(true));
ObjectTypeDB::bind_method(_MD("set_connection","connection:StreamPeer"),&HTTPClient::set_connection);
ObjectTypeDB::bind_method(_MD("request","method","url","headers","body"),&HTTPClient::request,DEFVAL(String()));
ObjectTypeDB::bind_method(_MD("send_body_text","body"),&HTTPClient::send_body_text);
@@ -601,6 +601,8 @@ void HTTPClient::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_status"),&HTTPClient::get_status);
ObjectTypeDB::bind_method(_MD("poll:Error"),&HTTPClient::poll);
+ ObjectTypeDB::bind_method(_MD("query_string_from_dict:String","fields"),&HTTPClient::query_string_from_dict);
+
BIND_CONSTANT( METHOD_GET );
BIND_CONSTANT( METHOD_HEAD );
@@ -689,6 +691,16 @@ void HTTPClient::set_read_chunk_size(int p_size) {
read_chunk_size=p_size;
}
+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]).http_escape() + "=" + String(p_dict[keys[i]]).http_escape();
+ }
+ query.erase(0, 1);
+ return query;
+}
+
HTTPClient::HTTPClient(){
tcp_connection = StreamPeerTCP::create_ref();
@@ -710,4 +722,3 @@ HTTPClient::~HTTPClient(){
}
-
diff --git a/core/io/http_client.h b/core/io/http_client.h
index 21281f38c5..b103dc43fc 100644
--- a/core/io/http_client.h
+++ b/core/io/http_client.h
@@ -192,6 +192,8 @@ public:
Error poll();
+ String query_string_from_dict(const Dictionary& p_dict);
+
HTTPClient();
~HTTPClient();
};
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 7582376fe0..2dffdf066c 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -3079,6 +3079,48 @@ String String::world_wrap(int p_chars_per_line) const {
return ret;
}
+String String::http_escape() const {
+ const CharString temp = utf8();
+ String res;
+ for (int i = 0; i < length(); ++i) {
+ CharType ord = temp[i];
+ if (ord == '.' || ord == '-' || ord == '_' || ord == '~' ||
+ (ord >= 'a' && ord <= 'z') ||
+ (ord >= 'A' && ord <= 'Z') ||
+ (ord >= '0' && ord <= '9')) {
+ res += ord;
+ } else {
+ char h_Val[3];
+ snprintf(h_Val, 3, "%.2X", ord);
+ res += "%";
+ res += h_Val;
+ }
+ }
+ return res;
+}
+
+String String::http_unescape() const {
+ String res;
+ for (int i = 0; i < length(); ++i) {
+ if (ord_at(i) == '%' && i+2 < length()) {
+ CharType ord1 = ord_at(i+1);
+ if ((ord1 >= '0' && ord1 <= '9') || (ord1 >= 'A' && ord1 <= 'Z')) {
+ CharType ord2 = ord_at(i+2);
+ if ((ord2 >= '0' && ord2 <= '9') || (ord2 >= 'A' && ord2 <= 'Z')) {
+ char bytes[2] = {ord1, ord2};
+ res += (char)strtol(bytes, NULL, 16);
+ i+=2;
+ }
+ } else {
+ res += ord_at(i);
+ }
+ } else {
+ res += ord_at(i);
+ }
+ }
+ return String::utf8(res.ascii());
+}
+
String String::c_unescape() const {
String escaped=*this;
diff --git a/core/ustring.h b/core/ustring.h
index fa25a07eb0..2f3c4bff4d 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -207,6 +207,8 @@ public:
String xml_escape(bool p_escape_quotes=false) const;
String xml_unescape() const;
+ String http_escape() const;
+ String http_unescape() const;
String c_escape() const;
String c_unescape() const;
String world_wrap(int p_chars_per_line) const;