1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

[Net] Fix WebSocketClient path parsing.

Recent changes to parse_url caused the client to make invalid HTTP
requests if no path was specified.

(cherry picked from commit d244dda597)
This commit is contained in:
Fabio Alessandrelli
2021-06-28 13:21:00 +02:00
committed by Rémi Verschelde
parent 91ea7530bd
commit 4994b3a99e
2 changed files with 7 additions and 3 deletions

View File

@@ -43,9 +43,9 @@ Error WebSocketClient::connect_to_url(String p_url, const Vector<String> p_proto
_is_multiplayer = gd_mp_api; _is_multiplayer = gd_mp_api;
String host = p_url; String host = p_url;
String path = "/"; String path;
String scheme = ""; String scheme;
int port = 80; int port = 0;
Error err = p_url.parse_url(scheme, host, port, path); Error err = p_url.parse_url(scheme, host, port, path);
ERR_FAIL_COND_V_MSG(err != OK, err, "Invalid URL: " + p_url); ERR_FAIL_COND_V_MSG(err != OK, err, "Invalid URL: " + p_url);
@@ -56,6 +56,9 @@ Error WebSocketClient::connect_to_url(String p_url, const Vector<String> p_proto
if (port == 0) { if (port == 0) {
port = ssl ? 443 : 80; port = ssl ? 443 : 80;
} }
if (path.empty()) {
path = "/";
}
return connect_to_host(host, path, port, ssl, p_protocols, p_custom_headers); return connect_to_host(host, path, port, ssl, p_protocols, p_custom_headers);
} }

View File

@@ -158,6 +158,7 @@ bool WSLClient::_verify_headers(String &r_protocol) {
Error WSLClient::connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, const Vector<String> p_protocols, const Vector<String> p_custom_headers) { Error WSLClient::connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, const Vector<String> p_protocols, const Vector<String> p_custom_headers) {
ERR_FAIL_COND_V(_connection.is_valid(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(_connection.is_valid(), ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(p_path.empty(), ERR_INVALID_PARAMETER);
_peer = Ref<WSLPeer>(memnew(WSLPeer)); _peer = Ref<WSLPeer>(memnew(WSLPeer));
IP_Address addr; IP_Address addr;