diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-05-03 13:55:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-03 13:55:57 +0200 |
commit | 015fc2ad4f23011540d84b2d513073f74619e6f3 (patch) | |
tree | f3c2fd47b781cb7a559bf3324b9a3ccbefdf7db8 /modules/websocket/websocket_client.cpp | |
parent | a4afa05efefba62673dfce2055cdf9bc9187905e (diff) | |
parent | 3bb40669d5efea707a90171ad2430a81fd4f4726 (diff) |
Merge pull request #48205 from Faless/net/4.x_url_parsing
[Net] Implement String::parse_url for parsing URLs.
Diffstat (limited to 'modules/websocket/websocket_client.cpp')
-rw-r--r-- | modules/websocket/websocket_client.cpp | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/modules/websocket/websocket_client.cpp b/modules/websocket/websocket_client.cpp index 425013f811..1e9183ebfa 100644 --- a/modules/websocket/websocket_client.cpp +++ b/modules/websocket/websocket_client.cpp @@ -43,34 +43,18 @@ Error WebSocketClient::connect_to_url(String p_url, const Vector<String> p_proto String host = p_url; String path = "/"; - int p_len = -1; + String scheme = ""; int port = 80; - bool ssl = false; - if (host.begins_with("wss://")) { - ssl = true; // we should implement this - host = host.substr(6, host.length() - 6); - port = 443; - } else { - ssl = false; - if (host.begins_with("ws://")) { - host = host.substr(5, host.length() - 5); - } - } + Error err = p_url.parse_url(scheme, host, port, path); + ERR_FAIL_COND_V_MSG(err != OK, err, "Invalid URL: " + p_url); - // Path - p_len = host.find("/"); - if (p_len != -1) { - path = host.substr(p_len, host.length() - p_len); - host = host.substr(0, p_len); + bool ssl = false; + if (scheme == "wss://") { + ssl = true; } - - // Port - p_len = host.rfind(":"); - if (p_len != -1 && p_len == host.find(":")) { - port = host.substr(p_len, host.length() - p_len).to_int(); - host = host.substr(0, p_len); + if (port == 0) { + port = ssl ? 443 : 80; } - return connect_to_host(host, path, port, ssl, p_protocols, p_custom_headers); } |