Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector<String> &p_headers, const PoolVector<uint8_t> &p_body) { ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(connection.is_null(), ERR_INVALID_DATA); static const char *_methods[METHOD_MAX] = { "GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "TRACE", "CONNECT" }; String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n"; if ((ssl && conn_port == 443) || (!ssl && conn_port == 80)) { // don't append the standard ports request += "Host: " + conn_host + "\r\n"; } else { request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n"; } bool add_clen = p_body.size() > 0; for (int i = 0; i < p_headers.size(); i++) { request += p_headers[i] + "\r\n"; if (add_clen && p_headers[i].find("Content-Length:") == 0) { add_clen = false; } } if (add_clen) { request += "Content-Length: " + itos(p_body.size()) + "\r\n"; //should it add utf8 encoding? not sure } request += "\r\n"; CharString cs = request.utf8(); PoolVector<uint8_t> data; //Maybe this goes faster somehow? for (int i = 0; i < cs.length(); i++) { data.append(cs[i]); } data.append_array(p_body); PoolVector<uint8_t>::Read r = data.read(); Error err = connection->put_data(&r[0], data.size()); if (err) { close(); status = STATUS_CONNECTION_ERROR; return err; } status = STATUS_REQUESTING; return OK; }
void GDAPI godot_pool_byte_array_append(godot_pool_byte_array *p_self, const uint8_t p_data) { PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; self->append(p_data); }
void GDAPI godot_pool_color_array_append(godot_pool_color_array *p_self, const godot_color *p_data) { PoolVector<Color> *self = (PoolVector<Color> *)p_self; Color &s = *(Color *)p_data; self->append(s); }
void GDAPI godot_pool_vector3_array_append(godot_pool_vector3_array *p_self, const godot_vector3 *p_data) { PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; Vector3 &s = *(Vector3 *)p_data; self->append(s); }
void GDAPI godot_pool_string_array_append(godot_pool_string_array *p_self, const godot_string *p_data) { PoolVector<String> *self = (PoolVector<String> *)p_self; String &s = *(String *)p_data; self->append(s); }
void GDAPI godot_pool_real_array_append(godot_pool_real_array *p_self, const godot_real p_data) { PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; self->append(p_data); }
Error LWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, PoolVector<String> p_protocols) { ERR_FAIL_COND_V(context != NULL, FAILED); IP_Address addr; if (!p_host.is_valid_ip_address()) { addr = IP::get_singleton()->resolve_hostname(p_host); } else { addr = p_host; } ERR_FAIL_COND_V(!addr.is_valid(), ERR_INVALID_PARAMETER); // prepare protocols if (p_protocols.size() == 0) // default to binary protocol p_protocols.append("binary"); _lws_make_protocols(this, &LWSClient::_lws_gd_callback, p_protocols, &_lws_ref); // init lws client struct lws_context_creation_info info; struct lws_client_connect_info i; memset(&i, 0, sizeof i); memset(&info, 0, sizeof info); info.port = CONTEXT_PORT_NO_LISTEN; info.protocols = _lws_ref->lws_structs; info.gid = -1; info.uid = -1; //info.ws_ping_pong_interval = 5; info.user = _lws_ref; #if defined(LWS_OPENSSL_SUPPORT) info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; #endif context = lws_create_context(&info); if (context == NULL) { _lws_free_ref(_lws_ref); _lws_ref = NULL; ERR_EXPLAIN("Unable to create lws context"); ERR_FAIL_V(FAILED); } char abuf[1024]; char hbuf[1024]; char pbuf[2048]; String addr_str = (String)addr; strncpy(abuf, addr_str.ascii().get_data(), 1024); strncpy(hbuf, p_host.utf8().get_data(), 1024); strncpy(pbuf, p_path.utf8().get_data(), 2048); i.context = context; i.protocol = _lws_ref->lws_names; i.address = abuf; i.host = hbuf; i.path = pbuf; i.port = p_port; if (p_ssl) { i.ssl_connection = LCCSCF_USE_SSL; if (!verify_ssl) i.ssl_connection |= LCCSCF_ALLOW_SELFSIGNED; } else { i.ssl_connection = 0; } lws_client_connect_via_info(&i); return OK; };