summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2016-12-13 10:57:05 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2016-12-13 11:09:37 +0100
commitd194e1c48e5d161f0310ee17e63f1951e2c50de6 (patch)
treef7e566071e123eed61c4af4f29dc32bd828ab632
parentde23ce11b51847b7b8bfc10ecf5926827516ac5a (diff)
Expose HTTP classes' set_ip_type to scripting
-rw-r--r--core/io/http_client.cpp11
-rw-r--r--core/io/http_client.h5
-rw-r--r--scene/main/http_request.cpp1
-rw-r--r--scene/main/http_request.h2
4 files changed, 12 insertions, 7 deletions
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 24314e3a1a..5420521f81 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -30,12 +30,13 @@
#include "io/stream_peer_ssl.h"
void HTTPClient::set_ip_type(IP::Type p_type) {
- tcp_connection->set_ip_type(p_type);
+ ip_type = p_type;
}
-Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_verify_host, IP::Type p_addr_type){
+Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_verify_host){
close();
+ tcp_connection->set_ip_type(ip_type);
conn_port=p_port;
conn_host=p_host;
@@ -65,7 +66,7 @@ Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_ve
status=STATUS_CONNECTING;
} else {
//is hostname
- resolving=IP::get_singleton()->resolve_hostname_queue_item(conn_host, p_addr_type);
+ resolving=IP::get_singleton()->resolve_hostname_queue_item(conn_host, ip_type);
status=STATUS_RESOLVING;
}
@@ -638,7 +639,8 @@ 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","verify_host"),&HTTPClient::connect,DEFVAL(false),DEFVAL(true),DEFVAL(IP::TYPE_ANY));
+ ObjectTypeDB::bind_method(_MD("set_ip_type","ip_type"),&HTTPClient::set_ip_type);
+ 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("get_connection:StreamPeer"),&HTTPClient::get_connection);
ObjectTypeDB::bind_method(_MD("request_raw","method","url","headers","body"),&HTTPClient::request_raw);
@@ -764,6 +766,7 @@ String HTTPClient::query_string_from_dict(const Dictionary& p_dict) {
HTTPClient::HTTPClient(){
+ ip_type = IP::TYPE_ANY;
tcp_connection = StreamPeerTCP::create_ref();
resolving = IP::RESOLVER_INVALID_ID;
status=STATUS_DISCONNECTED;
diff --git a/core/io/http_client.h b/core/io/http_client.h
index 7ec418fd23..fdbf47b9cc 100644
--- a/core/io/http_client.h
+++ b/core/io/http_client.h
@@ -132,6 +132,7 @@ public:
private:
+ IP::Type ip_type;
Status status;
IP::ResolverID resolving;
int conn_port;
@@ -164,9 +165,9 @@ private:
public:
- virtual void set_ip_type(IP::Type p_type);
+ void set_ip_type(IP::Type p_type);
//Error connect_and_get(const String& p_url,bool p_verify_host=true); //connects to a full url and perform request
- Error connect(const String &p_host,int p_port,bool p_ssl=false,bool p_verify_host=true, IP::Type p_addr_type = IP::TYPE_ANY);
+ Error connect(const String &p_host,int p_port,bool p_ssl=false,bool p_verify_host=true);
void set_connection(const Ref<StreamPeer>& p_connection);
Ref<StreamPeer> get_connection() const;
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index 4667812312..46ab385954 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.cpp
@@ -539,6 +539,7 @@ int HTTPRequest::get_body_size() const{
void HTTPRequest::_bind_methods() {
+ ObjectTypeDB::bind_method(_MD("set_ip_type","ip_type"),&HTTPRequest::set_ip_type);
ObjectTypeDB::bind_method(_MD("request","url","custom_headers","ssl_validate_domain","method","request_data"),&HTTPRequest::request,DEFVAL(StringArray()),DEFVAL(true),DEFVAL(HTTPClient::METHOD_GET),DEFVAL(String()));
ObjectTypeDB::bind_method(_MD("cancel_request"),&HTTPRequest::cancel_request);
diff --git a/scene/main/http_request.h b/scene/main/http_request.h
index 4dd79234b0..978ad3428b 100644
--- a/scene/main/http_request.h
+++ b/scene/main/http_request.h
@@ -116,7 +116,7 @@ protected:
static void _bind_methods();
public:
- virtual void set_ip_type(IP::Type p_type);
+ void set_ip_type(IP::Type p_type);
Error request(const String& p_url, const Vector<String>& p_custom_headers=Vector<String>(), bool p_ssl_validate_domain=true, HTTPClient::Method p_method=HTTPClient::METHOD_GET, const String& p_request_data=""); //connects to a full url and perform request
void cancel_request();
HTTPClient::Status get_http_client_status() const;