From def974818f452fdc1bfc1ffbe869a9eb6a0b6843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Thu, 4 Jul 2024 12:51:58 +0200 Subject: [PATCH] socket: Support IPv6 addresses in negotiate_connection() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Håvard Sørbø --- lib/base/socket.vala | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/base/socket.vala b/lib/base/socket.vala index 1868ee313..528b3a9c3 100644 --- a/lib/base/socket.vala +++ b/lib/base/socket.vala @@ -152,11 +152,10 @@ namespace Frida { var request = new StringBuilder.sized (256); request.append ("GET /ws HTTP/1.1\r\n"); string protocol = (transport == TLS) ? "wss" : "ws"; - string canonical_host = canonicalize_host (host); - string uri = protocol + "://" + canonical_host + "/ws"; - var msg = new Soup.Message ("GET", uri); + var uri = Uri.build (UriFlags.NONE, protocol, null, host, -1, "/ws", null, null); + var msg = new Soup.Message.from_uri ("GET", uri); Soup.websocket_client_prepare_handshake (msg, origin, null, null); - msg.request_headers.replace ("Host", canonical_host); + msg.request_headers.replace ("Host", make_host_header_value (uri)); msg.request_headers.replace ("User-Agent", "Frida/" + _version_string ()); msg.request_headers.foreach ((name, val) => { request.append (name + ": " + val + "\r\n"); @@ -220,13 +219,9 @@ namespace Frida { return connection; } - private string canonicalize_host (string raw_host) { - if (raw_host.has_suffix (":80") || raw_host.has_suffix (":443")) { - string[] tokens = raw_host.split (":", 2); - return tokens[0]; - } - - return raw_host; + private string make_host_header_value (Uri uri) { + unowned string host = uri.get_host (); + return Hostname.is_ip_address (host) ? @"[$host]" : host; } public class WebService : Object {