[libsoup/wip/soup-uri-removal] WIP: Replace SoupURI with GUri




commit 4ff2bc9d1c5c40bc7ca8cebf2422671a70561d16
Author: Patrick Griffis <pgriffis igalia com>
Date:   Mon Jul 27 18:07:37 2020 +0400

    WIP: Replace SoupURI with GUri

 docs/reference/libsoup-3.0-sections.txt       |   50 +-
 examples/get.c                                |   29 +-
 examples/simple-httpd.c                       |    6 +-
 examples/simple-proxy.c                       |   10 +-
 libsoup/Soup-3.0.metadata                     |    3 -
 libsoup/auth/soup-auth-basic.c                |    4 +-
 libsoup/auth/soup-auth-digest.c               |   21 +-
 libsoup/auth/soup-auth-domain-digest.c        |   12 +-
 libsoup/auth/soup-auth-domain.c               |    2 +-
 libsoup/auth/soup-auth-manager.c              |   29 +-
 libsoup/auth/soup-auth-manager.h              |    2 +-
 libsoup/auth/soup-auth-negotiate.c            |   26 +-
 libsoup/auth/soup-auth-ntlm.c                 |    6 +-
 libsoup/auth/soup-auth.c                      |    9 +-
 libsoup/auth/soup-auth.h                      |    4 +-
 libsoup/cache/soup-cache.c                    |    8 +-
 libsoup/cookies/soup-cookie-jar.c             |   74 +-
 libsoup/cookies/soup-cookie-jar.h             |   22 +-
 libsoup/cookies/soup-cookie.c                 |   47 +-
 libsoup/cookies/soup-cookie.h                 |    4 +-
 libsoup/hsts/soup-hsts-enforcer.c             |   49 +-
 libsoup/hsts/soup-hsts-enforcer.h             |    2 +-
 libsoup/hsts/soup-hsts-policy.c               |    4 +-
 libsoup/soup-connection.c                     |   26 +-
 libsoup/soup-connection.h                     |    4 +-
 libsoup/soup-directory-input-stream.c         |    4 +-
 libsoup/soup-directory-input-stream.h         |    2 +-
 libsoup/soup-form.c                           |   30 +-
 libsoup/soup-headers.c                        |    4 +-
 libsoup/soup-logger.c                         |   26 +-
 libsoup/soup-message-client-io.c              |   26 +-
 libsoup/soup-message-io.c                     |    4 +-
 libsoup/soup-message-private.h                |    6 +-
 libsoup/soup-message-server-io.c              |   65 +-
 libsoup/soup-message.c                        |   94 +-
 libsoup/soup-message.h                        |   14 +-
 libsoup/soup-misc.h                           |    2 -
 libsoup/soup-request-data.c                   |   23 +-
 libsoup/soup-request-file.c                   |   15 +-
 libsoup/soup-request-http.c                   |    4 +-
 libsoup/soup-request.c                        |   18 +-
 libsoup/soup-request.h                        |    4 +-
 libsoup/soup-server.c                         |   63 +-
 libsoup/soup-session-private.h                |    3 +-
 libsoup/soup-session.c                        |  155 ++-
 libsoup/soup-session.h                        |    4 +-
 libsoup/soup-socket-private.h                 |    2 +-
 libsoup/soup-socket.c                         |    8 +-
 libsoup/soup-uri.c                            | 1571 ++++++++-----------------
 libsoup/soup-uri.h                            |  121 +-
 libsoup/websocket/soup-websocket-connection.c |   14 +-
 libsoup/websocket/soup-websocket-connection.h |    6 +-
 meson.build                                   |    2 +-
 tests/auth-test.c                             |   48 +-
 tests/cache-test.c                            |   40 +-
 tests/chunk-io-test.c                         |    4 +-
 tests/coding-test.c                           |   12 +-
 tests/connection-test.c                       |   36 +-
 tests/context-test.c                          |    6 +-
 tests/continue-test.c                         |   24 +-
 tests/cookies-test.c                          |   82 +-
 tests/forms-test.c                            |   37 +-
 tests/hsts-db-test.c                          |   27 +-
 tests/hsts-test.c                             |   27 +-
 tests/misc-test.c                             |   68 +-
 tests/multipart-test.c                        |    6 +-
 tests/no-ssl-test.c                           |   32 +-
 tests/ntlm-test.c                             |   24 +-
 tests/proxy-test.c                            |   48 +-
 tests/range-test.c                            |    6 +-
 tests/redirect-test.c                         |   35 +-
 tests/request-body-test.c                     |   13 +-
 tests/samesite-test.c                         |   12 +-
 tests/server-auth-test.c                      |   22 +-
 tests/server-test.c                           |  130 +-
 tests/session-test.c                          |   23 +-
 tests/sniffing-test.c                         |   96 +-
 tests/socket-test.c                           |    8 +-
 tests/ssl-test.c                              |   13 +-
 tests/streaming-test.c                        |   18 +-
 tests/test-utils.c                            |   40 +-
 tests/test-utils.h                            |    5 +-
 tests/timeout-test.c                          |   37 +-
 tests/uri-parsing-test.c                      |  452 ++++---
 tests/websocket-test.c                        |   12 +-
 85 files changed, 1771 insertions(+), 2415 deletions(-)
---
diff --git a/docs/reference/libsoup-3.0-sections.txt b/docs/reference/libsoup-3.0-sections.txt
index 4b1d56ac..50a4bc51 100644
--- a/docs/reference/libsoup-3.0-sections.txt
+++ b/docs/reference/libsoup-3.0-sections.txt
@@ -554,56 +554,8 @@ soup_auth_manager_get_type
 
 <SECTION>
 <FILE>soup-uri</FILE>
-<TITLE>SoupURI</TITLE>
-SoupURI
-soup_uri_new_with_base
-soup_uri_new
-soup_uri_to_string
-<SUBSECTION>
-soup_uri_copy
-soup_uri_copy_host
-soup_uri_equal
-soup_uri_host_equal
-soup_uri_host_hash
-soup_uri_free
-<SUBSECTION>
-soup_uri_encode
-soup_uri_decode
-soup_uri_normalize
 <SUBSECTION>
-SOUP_URI_SCHEME_HTTP
-SOUP_URI_SCHEME_HTTPS
-SOUP_URI_SCHEME_DATA
-SOUP_URI_SCHEME_FILE
-SOUP_URI_SCHEME_FTP
-SOUP_URI_SCHEME_RESOURCE
-SOUP_URI_SCHEME_WS
-SOUP_URI_SCHEME_WSS
-soup_uri_uses_default_port
-SOUP_URI_IS_VALID
-SOUP_URI_VALID_FOR_HTTP
-<SUBSECTION>
-soup_uri_set_scheme
-soup_uri_get_scheme
-soup_uri_set_user
-soup_uri_get_user
-soup_uri_set_password
-soup_uri_get_password
-soup_uri_set_host
-soup_uri_get_host
-soup_uri_set_port
-soup_uri_get_port
-soup_uri_set_path
-soup_uri_get_path
-soup_uri_set_query
-soup_uri_set_query_from_form
-soup_uri_set_query_from_fields
-soup_uri_get_query
-soup_uri_set_fragment
-soup_uri_get_fragment
-<SUBSECTION Standard>
-SOUP_TYPE_URI
-soup_uri_get_type
+soup_uri_normalize
 </SECTION>
 
 <SECTION>
diff --git a/examples/get.c b/examples/get.c
index 67e72f2a..1a94fe96 100644
--- a/examples/get.c
+++ b/examples/get.c
@@ -39,7 +39,7 @@ get_url (const char *url)
         soup_session_queue_message (session, msg, finished, loop);
         g_main_loop_run (loop);
 
-       name = soup_message_get_uri (msg)->path;
+       name = g_uri_get_path (soup_message_get_uri (msg));
 
        if (!debug) {
                if (msg->status_code == SOUP_STATUS_SSL_FAILED) {
@@ -57,17 +57,18 @@ get_url (const char *url)
                header = soup_message_headers_get_one (msg->response_headers,
                                                       "Location");
                if (header) {
-                       SoupURI *uri;
+                       GUri *uri;
                        char *uri_string;
 
                        if (!debug && !quiet)
                                g_print ("  -> %s\n", header);
 
-                       uri = soup_uri_new_with_base (soup_message_get_uri (msg), header);
-                       uri_string = soup_uri_to_string (uri, FALSE);
+                       uri = g_uri_parse_relative (soup_message_get_uri (msg), header, SOUP_HTTP_URI_FLAGS, 
NULL);
+                        g_assert (uri != NULL);
+                       uri_string = g_uri_to_string (uri);
                        get_url (uri_string);
                        g_free (uri_string);
-                       soup_uri_free (uri);
+                       g_uri_unref (uri);
                }
        } else if (!head && SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
                if (output_file_path) {
@@ -190,7 +191,7 @@ main (int argc, char **argv)
 {
        GOptionContext *opts;
        const char *url;
-       SoupURI *proxy_uri, *parsed;
+       GUri *proxy_uri, *parsed;
        GError *error = NULL;
        SoupLogger *logger = NULL;
        char *help;
@@ -216,12 +217,12 @@ main (int argc, char **argv)
        g_option_context_free (opts);
 
        url = argv[1];
-       parsed = soup_uri_new (url);
+       parsed = g_uri_parse (url, SOUP_HTTP_URI_FLAGS, &error);
        if (!parsed) {
-               g_printerr ("Could not parse '%s' as a URL\n", url);
+               g_printerr ("Could not parse '%s' as a URL: %s\n", url, error->message);
                exit (1);
        }
-       soup_uri_free (parsed);
+       g_uri_unref (parsed);
 
        session = g_object_new (SOUP_TYPE_SESSION,
                                SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER,
@@ -258,10 +259,12 @@ main (int argc, char **argv)
 
        if (proxy) {
                GProxyResolver *resolver;
-               proxy_uri = soup_uri_new (proxy);
+                GError *error;
+               proxy_uri = g_uri_parse (proxy, SOUP_HTTP_URI_FLAGS, &error);
                if (!proxy_uri) {
-                       g_printerr ("Could not parse '%s' as URI\n",
-                                   proxy);
+                       g_printerr ("Could not parse '%s' as URI: %s\n",
+                                   proxy, error->message);
+                        g_error_free (error);
                        exit (1);
                }
 
@@ -269,7 +272,7 @@ main (int argc, char **argv)
                g_object_set (G_OBJECT (session),
                              SOUP_SESSION_PROXY_RESOLVER, resolver,
                              NULL);
-               soup_uri_free (proxy_uri);
+               g_uri_unref (proxy_uri);
                g_object_unref (resolver);
        }
 
diff --git a/examples/simple-httpd.c b/examples/simple-httpd.c
index 9d280ac3..10705193 100644
--- a/examples/simple-httpd.c
+++ b/examples/simple-httpd.c
@@ -93,7 +93,7 @@ do_get (SoupServer *server, SoupMessage *msg, const char *path)
                if (!slash || slash[1]) {
                        char *redir_uri;
 
-                       redir_uri = g_strdup_printf ("%s/", soup_message_get_uri (msg)->path);
+                       redir_uri = g_strdup_printf ("%s/", g_uri_get_path (soup_message_get_uri (msg)));
                        soup_message_set_redirect (msg, SOUP_STATUS_MOVED_PERMANENTLY,
                                                   redir_uri);
                        g_free (redir_uri);
@@ -287,10 +287,10 @@ main (int argc, char **argv)
 
        uris = soup_server_get_uris (server);
        for (u = uris; u; u = u->next) {
-               str = soup_uri_to_string (u->data, FALSE);
+               str = g_uri_to_string (u->data);
                g_print ("Listening on %s\n", str);
                g_free (str);
-               soup_uri_free (u->data);
+               g_uri_unref (u->data);
        }
        g_slist_free (uris);
 
diff --git a/examples/simple-proxy.c b/examples/simple-proxy.c
index b1f2abde..c2581a52 100644
--- a/examples/simple-proxy.c
+++ b/examples/simple-proxy.c
@@ -209,7 +209,7 @@ static void
 try_tunnel (SoupServer *server, SoupMessage *msg, SoupClientContext *context)
 {
        Tunnel *tunnel;
-       SoupURI *dest_uri;
+       GUri *dest_uri;
        GSocketClient *sclient;
 
        soup_server_pause_message (server, msg);
@@ -221,7 +221,7 @@ try_tunnel (SoupServer *server, SoupMessage *msg, SoupClientContext *context)
 
        dest_uri = soup_message_get_uri (msg);
        sclient = g_socket_client_new ();
-       g_socket_client_connect_to_host_async (sclient, dest_uri->host, dest_uri->port,
+       g_socket_client_connect_to_host_async (sclient, g_uri_get_host (dest_uri), g_uri_get_port (dest_uri),
                                               NULL, tunnel_connected_cb, tunnel);
        g_object_unref (sclient);
 }
@@ -284,7 +284,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
        SoupMessage *msg2;
        char *uristr;
 
-       uristr = soup_uri_to_string (soup_message_get_uri (msg), FALSE);
+       uristr = g_uri_to_string (soup_message_get_uri (msg));
        g_print ("[%p] %s %s HTTP/1.%d\n", msg, msg->method, uristr,
                 soup_message_get_http_version (msg));
 
@@ -398,10 +398,10 @@ main (int argc, char **argv)
 
        uris = soup_server_get_uris (server);
        for (u = uris; u; u = u->next) {
-               str = soup_uri_to_string (u->data, FALSE);
+               str = g_uri_to_string (u->data);
                g_print ("Listening on %s\n", str);
                g_free (str);
-               soup_uri_free (u->data);
+               g_uri_unref (u->data);
        }
        g_slist_free (uris);
 
diff --git a/libsoup/Soup-3.0.metadata b/libsoup/Soup-3.0.metadata
index b2e58984..f8c245d4 100644
--- a/libsoup/Soup-3.0.metadata
+++ b/libsoup/Soup-3.0.metadata
@@ -29,9 +29,6 @@ Session
        .get_features type_arguments="weak Soup.SessionFeature"
        .send_async.cancellable#parameter default=null
 Session*.new_with_options skip=false
-URI
-       .set_query_from_fields skip=false
-// uri_host_*.* type="Soup.URI"
 
 // Not enough GIR information
 MessageBody.data type="uint8[]" array_length_field="length"
diff --git a/libsoup/auth/soup-auth-basic.c b/libsoup/auth/soup-auth-basic.c
index db13124c..e9aa346b 100644
--- a/libsoup/auth/soup-auth-basic.c
+++ b/libsoup/auth/soup-auth-basic.c
@@ -70,11 +70,11 @@ soup_auth_basic_update (SoupAuth *auth, SoupMessage *msg,
 }
 
 static GSList *
-soup_auth_basic_get_protection_space (SoupAuth *auth, SoupURI *source_uri)
+soup_auth_basic_get_protection_space (SoupAuth *auth, GUri *source_uri)
 {
        char *space, *p;
 
-       space = g_strdup (source_uri->path);
+       space = g_strdup (g_uri_get_path (source_uri));
 
        /* Strip filename component */
        p = strrchr (space, '/');
diff --git a/libsoup/auth/soup-auth-digest.c b/libsoup/auth/soup-auth-digest.c
index 06439ea3..58fe18ed 100644
--- a/libsoup/auth/soup-auth-digest.c
+++ b/libsoup/auth/soup-auth-digest.c
@@ -186,12 +186,12 @@ soup_auth_digest_update (SoupAuth *auth, SoupMessage *msg,
 }
 
 static GSList *
-soup_auth_digest_get_protection_space (SoupAuth *auth, SoupURI *source_uri)
+soup_auth_digest_get_protection_space (SoupAuth *auth, GUri *source_uri)
 {
        SoupAuthDigest *auth_digest = SOUP_AUTH_DIGEST (auth);
        SoupAuthDigestPrivate *priv = soup_auth_digest_get_instance_private (auth_digest);
        GSList *space = NULL;
-       SoupURI *uri;
+       GUri *uri;
        char **dvec, *d, *dir, *slash;
        int dix;
 
@@ -208,15 +208,16 @@ soup_auth_digest_get_protection_space (SoupAuth *auth, SoupURI *source_uri)
                if (*d == '/')
                        dir = g_strdup (d);
                else {
-                       uri = soup_uri_new (d);
-                       if (uri && uri->scheme == source_uri->scheme &&
-                           uri->port == source_uri->port &&
-                           !strcmp (uri->host, source_uri->host))
-                               dir = g_strdup (uri->path);
+                       uri = soup_uri_parse_normalized (NULL, d, NULL);
+                       if (uri &&
+                            !g_ascii_strcasecmp (g_uri_get_scheme (uri), g_uri_get_scheme (source_uri)) &&
+                           g_uri_get_port (uri) == g_uri_get_port (source_uri) &&
+                           !strcmp (g_uri_get_host (uri), g_uri_get_host (source_uri)))
+                               dir = g_strdup (g_uri_get_path (uri));
                        else
                                dir = NULL;
                        if (uri)
-                               soup_uri_free (uri);
+                               g_uri_unref (uri);
                }
 
                if (dir) {
@@ -417,11 +418,11 @@ soup_auth_digest_get_authorization (SoupAuth *auth, SoupMessage *msg)
        char response[33], *token;
        char *url, *algorithm;
        GString *out;
-       SoupURI *uri;
+       GUri *uri;
 
        uri = soup_message_get_uri (msg);
        g_return_val_if_fail (uri != NULL, NULL);
-       url = soup_uri_to_string (uri, TRUE);
+       url = soup_uri_get_path_and_query (uri);
 
        soup_auth_digest_compute_response (msg->method, url, priv->hex_a1,
                                           priv->qop, priv->nonce,
diff --git a/libsoup/auth/soup-auth-domain-digest.c b/libsoup/auth/soup-auth-domain-digest.c
index ae9fa266..8aca2f3f 100644
--- a/libsoup/auth/soup-auth-domain-digest.c
+++ b/libsoup/auth/soup-auth-domain-digest.c
@@ -199,7 +199,7 @@ check_hex_urp (SoupAuthDomain *domain, SoupMessage *msg,
        const char *nonce, *nc, *cnonce, *response;
        char hex_a1[33], computed_response[33];
        int nonce_count;
-       SoupURI *dig_uri, *req_uri;
+       GUri *dig_uri, *req_uri;
 
        msg_username = g_hash_table_lookup (params, "username");
        if (!msg_username || strcmp (msg_username, username) != 0)
@@ -211,19 +211,19 @@ check_hex_urp (SoupAuthDomain *domain, SoupMessage *msg,
                return FALSE;
 
        req_uri = soup_message_get_uri (msg);
-       dig_uri = soup_uri_new (uri);
+       dig_uri = soup_uri_parse_normalized (NULL, uri, NULL);
        if (dig_uri) {
                if (!soup_uri_equal (dig_uri, req_uri)) {
-                       soup_uri_free (dig_uri);
+                       g_uri_unref (dig_uri);
                        return FALSE;
                }
-               soup_uri_free (dig_uri);
+               g_uri_unref (dig_uri);
        } else {
                char *req_path;
                char *dig_path;
 
-               req_path = soup_uri_to_string (req_uri, TRUE);
-               dig_path = soup_uri_decode (uri);
+               req_path = soup_uri_get_path_and_query (req_uri);
+               dig_path = g_uri_unescape_string (uri, NULL);
 
                if (strcmp (dig_path, req_path) != 0) {
                        g_free (req_path);
diff --git a/libsoup/auth/soup-auth-domain.c b/libsoup/auth/soup-auth-domain.c
index 8785c474..44a4065a 100644
--- a/libsoup/auth/soup-auth-domain.c
+++ b/libsoup/auth/soup-auth-domain.c
@@ -562,7 +562,7 @@ soup_auth_domain_covers (SoupAuthDomain *domain, SoupMessage *msg)
        const char *path;
 
        if (!priv->proxy) {
-               path = soup_message_get_uri (msg)->path;
+               path = g_uri_get_path (soup_message_get_uri (msg));
                if (!soup_path_map_lookup (priv->paths, path))
                        return FALSE;
        }
diff --git a/libsoup/auth/soup-auth-manager.c b/libsoup/auth/soup-auth-manager.c
index 34780b05..80c52f4a 100644
--- a/libsoup/auth/soup-auth-manager.c
+++ b/libsoup/auth/soup-auth-manager.c
@@ -71,7 +71,7 @@ typedef struct {
 } SoupAuthManagerPrivate;
 
 typedef struct {
-       SoupURI     *uri;
+       GUri        *uri;
        SoupPathMap *auth_realms;      /* path -> scheme:realm */
        GHashTable  *auths;            /* scheme:realm -> SoupAuth */
 } SoupAuthHost;
@@ -83,7 +83,7 @@ G_DEFINE_TYPE_WITH_CODE (SoupAuthManager, soup_auth_manager, G_TYPE_OBJECT,
 
 static void soup_auth_host_free (SoupAuthHost *host);
 static SoupAuth *record_auth_for_uri (SoupAuthManagerPrivate *priv,
-                                     SoupURI *uri, SoupAuth *auth,
+                                     GUri *uri, SoupAuth *auth,
                                      gboolean prior_auth_failed);
 
 static void
@@ -396,7 +396,7 @@ check_auth (SoupMessage *msg, SoupAuth *auth)
 }
 
 static SoupAuthHost *
-get_auth_host_for_uri (SoupAuthManagerPrivate *priv, SoupURI *uri)
+get_auth_host_for_uri (SoupAuthManagerPrivate *priv, GUri *uri)
 {
        SoupAuthHost *host;
 
@@ -417,7 +417,7 @@ soup_auth_host_free (SoupAuthHost *host)
        g_clear_pointer (&host->auth_realms, soup_path_map_free);
        g_clear_pointer (&host->auths, g_hash_table_destroy);
 
-       soup_uri_free (host->uri);
+       g_uri_unref (host->uri);
        g_slice_free (SoupAuthHost, host);
 }
 
@@ -430,7 +430,7 @@ make_auto_ntlm_auth (SoupAuthManagerPrivate *priv, SoupAuthHost *host)
                return FALSE;
 
        auth = g_object_new (SOUP_TYPE_AUTH_NTLM,
-                            SOUP_AUTH_HOST, host->uri->host,
+                            SOUP_AUTH_HOST, g_uri_get_host (host->uri),
                             NULL);
        record_auth_for_uri (priv, host->uri, auth, FALSE);
        g_object_unref (auth);
@@ -484,7 +484,7 @@ lookup_auth (SoupAuthManagerPrivate *priv, SoupMessage *msg)
        if (!host->auth_realms)
                return NULL;
 
-       path = soup_message_get_uri (msg)->path;
+       path = g_uri_get_path (soup_message_get_uri (msg));
        if (!path)
                path = "/";
        realm = soup_path_map_lookup (host->auth_realms, path);
@@ -516,7 +516,7 @@ authenticate_auth (SoupAuthManager *manager, SoupAuth *auth,
                   gboolean proxy, gboolean can_interact)
 {
         SoupAuthManagerPrivate *priv = soup_auth_manager_get_instance_private (manager);
-       SoupURI *uri;
+       GUri *uri;
 
        if (!soup_auth_can_authenticate (auth))
                return;
@@ -531,10 +531,11 @@ authenticate_auth (SoupAuthManager *manager, SoupAuth *auth,
        /* If a password is specified explicitly in the URI, use it
         * even if the auth had previously already been authenticated.
         */
-       if (uri->password && uri->user) {
-               soup_auth_authenticate (auth, uri->user, uri->password);
-               soup_uri_set_password (uri, NULL);
-               soup_uri_set_user (uri, NULL);
+       if (g_uri_get_password (uri) && g_uri_get_user (uri)) {
+               soup_auth_authenticate (auth, g_uri_get_user (uri), g_uri_get_password (uri));
+                GUri *new_uri = soup_uri_copy_with_credentials (uri, NULL, NULL);
+                soup_message_set_uri (msg, new_uri); // QUESTION: This didn't emit a signal previously
+                g_uri_unref (new_uri);
        } else if (!soup_auth_is_authenticated (auth) && can_interact) {
                g_signal_emit (manager, signals[AUTHENTICATE], 0,
                               msg, auth, prior_auth_failed);
@@ -542,7 +543,7 @@ authenticate_auth (SoupAuthManager *manager, SoupAuth *auth,
 }
 
 static SoupAuth *
-record_auth_for_uri (SoupAuthManagerPrivate *priv, SoupURI *uri,
+record_auth_for_uri (SoupAuthManagerPrivate *priv, GUri *uri,
                     SoupAuth *auth, gboolean prior_auth_failed)
 {
        SoupAuthHost *host;
@@ -785,7 +786,7 @@ soup_auth_manager_request_unqueued (SoupSessionFeature *manager,
 /**
  * soup_auth_manager_use_auth:
  * @manager: a #SoupAuthManager
- * @uri: the #SoupURI under which @auth is to be used
+ * @uri: the #GUri under which @auth is to be used
  * @auth: the #SoupAuth to use
  *
  * Records that @auth is to be used under @uri, as though a
@@ -802,7 +803,7 @@ soup_auth_manager_request_unqueued (SoupSessionFeature *manager,
  */
 void
 soup_auth_manager_use_auth (SoupAuthManager *manager,
-                           SoupURI         *uri,
+                           GUri            *uri,
                            SoupAuth        *auth)
 {
         SoupAuthManagerPrivate *priv = soup_auth_manager_get_instance_private (manager);
diff --git a/libsoup/auth/soup-auth-manager.h b/libsoup/auth/soup-auth-manager.h
index c17c921c..2901d410 100644
--- a/libsoup/auth/soup-auth-manager.h
+++ b/libsoup/auth/soup-auth-manager.h
@@ -24,7 +24,7 @@ struct _SoupAuthManagerClass {
 
 SOUP_AVAILABLE_IN_2_4
 void  soup_auth_manager_use_auth (SoupAuthManager *manager,
-                                 SoupURI         *uri,
+                                 GUri            *uri,
                                  SoupAuth        *auth);
 
 SOUP_AVAILABLE_IN_2_58
diff --git a/libsoup/auth/soup-auth-negotiate.c b/libsoup/auth/soup-auth-negotiate.c
index de4a778d..65c0ec74 100644
--- a/libsoup/auth/soup-auth-negotiate.c
+++ b/libsoup/auth/soup-auth-negotiate.c
@@ -142,11 +142,11 @@ soup_auth_negotiate_free_connection_state (SoupConnectionAuth *auth,
 }
 
 static GSList *
-soup_auth_negotiate_get_protection_space (SoupAuth *auth, SoupURI *source_uri)
+soup_auth_negotiate_get_protection_space (SoupAuth *auth, GUri *source_uri)
 {
        char *space, *p;
 
-       space = g_strdup (source_uri->path);
+       space = g_strdup (g_uri_get_path (source_uri));
 
        /* Strip filename component */
        p = strrchr (space, '/');
@@ -397,18 +397,18 @@ check_server_response (SoupMessage *msg, gpointer auth)
 
 /* Check if scheme://host:port from message matches the given URI. */
 static gint
-match_base_uri (SoupURI *list_uri, SoupURI *msg_uri)
+match_base_uri (GUri *list_uri, GUri *msg_uri)
 {
-       if (msg_uri->scheme != list_uri->scheme)
-               return 1;
+        if (g_strcmp0 (g_uri_get_scheme (list_uri), g_uri_get_scheme (msg_uri)))
+                return 1;
 
-       if (list_uri->port && (msg_uri->port != list_uri->port))
-               return 1;
+        if (g_uri_get_port (list_uri) != -1 && g_uri_get_port (list_uri) != g_uri_get_port (msg_uri))
+                return 1;
 
-       if (list_uri->host)
-               return !soup_host_matches_host (msg_uri->host, list_uri->host);
+        if (g_uri_get_host (list_uri))
+                return !soup_host_matches_host (g_uri_get_host (msg_uri), g_uri_get_host (list_uri));
 
-       return 0;
+        return 0;
 }
 
 /* Parses a comma separated list of URIS from the environment. */
@@ -431,10 +431,10 @@ parse_uris_from_env_variable (const gchar *env_variable, GSList **list)
 
        length = g_strv_length (uris);
        for (i = 0; i < length; i++) {
-               SoupURI *uri;
+               GUri *uri;
 
                /* If the supplied URI is valid, append it to the list */
-               if ((uri = soup_uri_new (uris[i])))
+               if ((uri = soup_uri_parse_normalized (NULL, uris[i], NULL)))
                        *list = g_slist_prepend (*list, uri);
        }
 
@@ -444,7 +444,7 @@ parse_uris_from_env_variable (const gchar *env_variable, GSList **list)
 static gboolean
 check_auth_trusted_uri (SoupConnectionAuth *auth, SoupMessage *msg)
 {
-       SoupURI *msg_uri;
+       GUri *msg_uri;
        GSList *matched = NULL;
 
        g_return_val_if_fail (auth != NULL, FALSE);
diff --git a/libsoup/auth/soup-auth-ntlm.c b/libsoup/auth/soup-auth-ntlm.c
index 7a9b7ac3..2d4fbf05 100644
--- a/libsoup/auth/soup-auth-ntlm.c
+++ b/libsoup/auth/soup-auth-ntlm.c
@@ -398,17 +398,17 @@ soup_auth_ntlm_update_connection (SoupConnectionAuth *auth, SoupMessage *msg,
 
        g_object_set (G_OBJECT (auth),
                      SOUP_AUTH_REALM, priv->domain,
-                     SOUP_AUTH_HOST, soup_message_get_uri (msg)->host,
+                     SOUP_AUTH_HOST, g_uri_get_host (soup_message_get_uri (msg)),
                      NULL);
        return success;
 }
 
 static GSList *
-soup_auth_ntlm_get_protection_space (SoupAuth *auth, SoupURI *source_uri)
+soup_auth_ntlm_get_protection_space (SoupAuth *auth, GUri *source_uri)
 {
        char *space, *p;
 
-       space = g_strdup (source_uri->path);
+       space = g_strdup (g_uri_get_path (source_uri));
 
        /* Strip filename component */
        p = strrchr (space, '/');
diff --git a/libsoup/auth/soup-auth.c b/libsoup/auth/soup-auth.c
index 7e5a5f70..8506096f 100644
--- a/libsoup/auth/soup-auth.c
+++ b/libsoup/auth/soup-auth.c
@@ -243,7 +243,7 @@ soup_auth_new (GType type, SoupMessage *msg, const char *auth_header)
 
        auth = g_object_new (type,
                             SOUP_AUTH_IS_FOR_PROXY, (msg->status_code == SOUP_STATUS_PROXY_UNAUTHORIZED),
-                            SOUP_AUTH_HOST, soup_message_get_uri (msg)->host,
+                            SOUP_AUTH_HOST, g_uri_get_host (soup_message_get_uri (msg)),
                             NULL);
 
        SoupAuthPrivate *priv = soup_auth_get_instance_private (auth);
@@ -538,12 +538,15 @@ soup_auth_can_authenticate (SoupAuth *auth)
  * paths, which can be freed with soup_auth_free_protection_space().
  **/
 GSList *
-soup_auth_get_protection_space (SoupAuth *auth, SoupURI *source_uri)
+soup_auth_get_protection_space (SoupAuth *auth, GUri *source_uri)
 {
        g_return_val_if_fail (SOUP_IS_AUTH (auth), NULL);
        g_return_val_if_fail (source_uri != NULL, NULL);
 
-       return SOUP_AUTH_GET_CLASS (auth)->get_protection_space (auth, source_uri);
+        GUri *normalized_source_uri = soup_normalize_uri (source_uri);
+       GSList *ret = SOUP_AUTH_GET_CLASS (auth)->get_protection_space (auth, source_uri);
+        g_uri_unref (normalized_source_uri);
+        return ret;
 }
 
 /**
diff --git a/libsoup/auth/soup-auth.h b/libsoup/auth/soup-auth.h
index c9b78933..22970c9c 100644
--- a/libsoup/auth/soup-auth.h
+++ b/libsoup/auth/soup-auth.h
@@ -25,7 +25,7 @@ struct _SoupAuthClass {
                                              GHashTable    *auth_header);
 
        GSList *     (*get_protection_space) (SoupAuth      *auth,
-                                             SoupURI       *source_uri);
+                                             GUri          *source_uri);
 
        void         (*authenticate)         (SoupAuth      *auth,
                                              const char    *username,
@@ -87,7 +87,7 @@ char       *soup_auth_get_authorization     (SoupAuth      *auth,
 
 SOUP_AVAILABLE_IN_2_4
 GSList     *soup_auth_get_protection_space  (SoupAuth      *auth,
-                                            SoupURI       *source_uri);
+                                            GUri          *source_uri);
 SOUP_AVAILABLE_IN_2_4
 void        soup_auth_free_protection_space (SoupAuth      *auth,
                                             GSList        *space);
diff --git a/libsoup/cache/soup-cache.c b/libsoup/cache/soup-cache.c
index 5a00467c..ab914ab0 100644
--- a/libsoup/cache/soup-cache.c
+++ b/libsoup/cache/soup-cache.c
@@ -210,7 +210,7 @@ get_cacheability (SoupCache *cache, SoupMessage *msg)
        }
 
        /* Section 13.9 */
-       if ((soup_message_get_uri (msg))->query &&
+       if ((g_uri_get_query (soup_message_get_uri (msg))) &&
            !soup_message_headers_get_one (msg->response_headers, "Expires") &&
            !has_max_age)
                return SOUP_CACHE_UNCACHEABLE;
@@ -465,7 +465,7 @@ soup_cache_entry_new (SoupCache *cache, SoupMessage *msg, time_t request_time, t
        entry->being_validated = FALSE;
        entry->status_code = msg->status_code;
        entry->response_time = response_time;
-       entry->uri = soup_uri_to_string (soup_message_get_uri (msg), FALSE);
+       entry->uri = g_uri_to_string_partial (soup_message_get_uri (msg), G_URI_HIDE_PASSWORD);
 
        /* Headers */
        entry->headers = soup_message_headers_new (SOUP_MESSAGE_HEADERS_RESPONSE);
@@ -662,7 +662,7 @@ soup_cache_entry_lookup (SoupCache *cache,
        guint32 key;
        char *uri = NULL;
 
-       uri = soup_uri_to_string (soup_message_get_uri (msg), FALSE);
+       uri = g_uri_to_string_partial (soup_message_get_uri (msg), G_URI_HIDE_PASSWORD);
        key = get_cache_key_from_uri ((const char *) uri);
 
        entry = g_hash_table_lookup (priv->cache, GUINT_TO_POINTER (key));
@@ -1364,7 +1364,7 @@ SoupMessage *
 soup_cache_generate_conditional_request (SoupCache *cache, SoupMessage *original)
 {
        SoupMessage *msg;
-       SoupURI *uri;
+       GUri *uri;
        SoupCacheEntry *entry;
        const char *last_modified, *etag;
        GList *disabled_features, *f;
diff --git a/libsoup/cookies/soup-cookie-jar.c b/libsoup/cookies/soup-cookie-jar.c
index 1cf24f3a..c43f22ca 100644
--- a/libsoup/cookies/soup-cookie-jar.c
+++ b/libsoup/cookies/soup-cookie-jar.c
@@ -286,9 +286,9 @@ compare_cookies (gconstpointer a, gconstpointer b, gpointer jar)
 static gboolean
 cookie_is_valid_for_same_site_policy (SoupCookie *cookie,
                                       gboolean    is_safe_method,
-                                      SoupURI    *uri,
-                                      SoupURI    *top_level,
-                                      SoupURI    *cookie_uri,
+                                      GUri       *uri,
+                                      GUri       *top_level,
+                                      GUri       *cookie_uri,
                                       gboolean    is_top_level_navigation,
                                       gboolean    for_http)
 {
@@ -307,14 +307,14 @@ cookie_is_valid_for_same_site_policy (SoupCookie *cookie,
        if (is_top_level_navigation && cookie_uri == NULL)
                return FALSE;
 
-       return soup_host_matches_host (soup_uri_get_host (cookie_uri ? cookie_uri : top_level), 
soup_uri_get_host (uri));
+       return soup_host_matches_host (g_uri_get_host (cookie_uri ? cookie_uri : top_level), g_uri_get_host 
(uri));
 }
 
 static GSList *
 get_cookies (SoupCookieJar *jar,
-             SoupURI       *uri,
-             SoupURI       *top_level,
-             SoupURI       *site_for_cookies,
+             GUri          *uri,
+             GUri          *top_level,
+             GUri          *site_for_cookies,
              gboolean       is_safe_method,
              gboolean       for_http,
              gboolean       is_top_level_navigation,
@@ -324,19 +324,20 @@ get_cookies (SoupCookieJar *jar,
        GSList *cookies, *domain_cookies;
        char *domain, *cur, *next_domain;
        GSList *new_head, *cookies_to_remove = NULL, *p;
+        const char *host = g_uri_get_host (uri);
 
        priv = soup_cookie_jar_get_instance_private (jar);
 
-       if (!uri->host || !uri->host[0])
+       if (!host || !host[0])
                return NULL;
 
        /* The logic here is a little weird, but the plan is that if
-        * uri->host is "www.foo.com", we will end up looking up
+        * host is "www.foo.com", we will end up looking up
         * cookies for ".www.foo.com", "www.foo.com", ".foo.com", and
         * ".com", in that order. (Logic stolen from Mozilla.)
         */
        cookies = NULL;
-       domain = cur = g_strdup_printf (".%s", uri->host);
+       domain = cur = g_strdup_printf (".%s", host);
        next_domain = domain + 1;
        do {
                new_head = domain_cookies = g_hash_table_lookup (priv->domains, cur);
@@ -380,7 +381,7 @@ get_cookies (SoupCookieJar *jar,
 /**
  * soup_cookie_jar_get_cookies:
  * @jar: a #SoupCookieJar
- * @uri: a #SoupURI
+ * @uri: a #GUri
  * @for_http: whether or not the return value is being passed directly
  * to an HTTP operation
  *
@@ -401,7 +402,7 @@ get_cookies (SoupCookieJar *jar,
  * Since: 2.24
  **/
 char *
-soup_cookie_jar_get_cookies (SoupCookieJar *jar, SoupURI *uri,
+soup_cookie_jar_get_cookies (SoupCookieJar *jar, GUri *uri,
                             gboolean for_http)
 {
        GSList *cookies;
@@ -427,7 +428,7 @@ soup_cookie_jar_get_cookies (SoupCookieJar *jar, SoupURI *uri,
 /**
  * soup_cookie_jar_get_cookie_list:
  * @jar: a #SoupCookieJar
- * @uri: a #SoupURI
+ * @uri: a #GUri
  * @for_http: whether or not the return value is being passed directly
  * to an HTTP operation
  *
@@ -448,7 +449,7 @@ soup_cookie_jar_get_cookies (SoupCookieJar *jar, SoupURI *uri,
  * Since: 2.40
  **/
 GSList *
-soup_cookie_jar_get_cookie_list (SoupCookieJar *jar, SoupURI *uri, gboolean for_http)
+soup_cookie_jar_get_cookie_list (SoupCookieJar *jar, GUri *uri, gboolean for_http)
 {
        g_return_val_if_fail (SOUP_IS_COOKIE_JAR (jar), NULL);
        g_return_val_if_fail (uri != NULL, NULL);
@@ -459,9 +460,9 @@ soup_cookie_jar_get_cookie_list (SoupCookieJar *jar, SoupURI *uri, gboolean for_
 /**
  * soup_cookie_jar_get_cookie_list_with_same_site_info:
  * @jar: a #SoupCookieJar
- * @uri: a #SoupURI
- * @top_level: (nullable): a #SoupURI for the top level document
- * @site_for_cookies: (nullable): a #SoupURI indicating the origin to get cookies for
+ * @uri: a #GUri
+ * @top_level: (nullable): a #GUri for the top level document
+ * @site_for_cookies: (nullable): a #GUri indicating the origin to get cookies for
  * @for_http: whether or not the return value is being passed directly
  * to an HTTP operation
  * @is_safe_method: if the HTTP method is safe, as defined by RFC 7231, ignored when @for_http is %FALSE
@@ -480,9 +481,9 @@ soup_cookie_jar_get_cookie_list (SoupCookieJar *jar, SoupURI *uri, gboolean for_
  */
 GSList *
 soup_cookie_jar_get_cookie_list_with_same_site_info (SoupCookieJar *jar,
-                                                     SoupURI       *uri,
-                                                     SoupURI       *top_level,
-                                                     SoupURI       *site_for_cookies,
+                                                     GUri          *uri,
+                                                     GUri          *top_level,
+                                                     GUri          *site_for_cookies,
                                                      gboolean       for_http,
                                                      gboolean       is_safe_method,
                                                      gboolean       is_top_level_navigation)
@@ -507,19 +508,24 @@ normalize_cookie_domain (const char *domain)
 static gboolean
 incoming_cookie_is_third_party (SoupCookieJar            *jar,
                                SoupCookie               *cookie,
-                               SoupURI                  *first_party,
+                               GUri                     *first_party,
                                SoupCookieJarAcceptPolicy policy)
 {
        SoupCookieJarPrivate *priv;
        const char *normalized_cookie_domain;
        const char *cookie_base_domain;
        const char *first_party_base_domain;
+        const char *first_party_host;
 
        if (policy != SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY &&
            policy != SOUP_COOKIE_JAR_ACCEPT_GRANDFATHERED_THIRD_PARTY)
                return FALSE;
 
-       if (first_party == NULL || first_party->host == NULL)
+       if (first_party == NULL)
+                return TRUE;
+
+        first_party_host = g_uri_get_host (first_party);
+        if (first_party_host == NULL)
                return TRUE;
 
        normalized_cookie_domain = normalize_cookie_domain (cookie->domain);
@@ -527,9 +533,9 @@ incoming_cookie_is_third_party (SoupCookieJar            *jar,
        if (cookie_base_domain == NULL)
                cookie_base_domain = cookie->domain;
 
-       first_party_base_domain = soup_tld_get_base_domain (first_party->host, NULL);
+       first_party_base_domain = soup_tld_get_base_domain (first_party_host, NULL);
        if (first_party_base_domain == NULL)
-               first_party_base_domain = first_party->host;
+               first_party_base_domain = first_party_host;
 
        if (soup_host_matches_host (cookie_base_domain, first_party_base_domain))
                return FALSE;
@@ -569,7 +575,7 @@ incoming_cookie_is_third_party (SoupCookieJar            *jar,
  * Since: 2.68
  **/
 void
-soup_cookie_jar_add_cookie_full (SoupCookieJar *jar, SoupCookie *cookie, SoupURI *uri, SoupURI *first_party)
+soup_cookie_jar_add_cookie_full (SoupCookieJar *jar, SoupCookie *cookie, GUri *uri, GUri *first_party)
 {
        SoupCookieJarPrivate *priv;
        GSList *old_cookies, *oc, *last = NULL;
@@ -692,7 +698,7 @@ soup_cookie_jar_add_cookie (SoupCookieJar *jar, SoupCookie *cookie)
  * Since: 2.40
  **/
 void
-soup_cookie_jar_add_cookie_with_first_party (SoupCookieJar *jar, SoupURI *first_party, SoupCookie *cookie)
+soup_cookie_jar_add_cookie_with_first_party (SoupCookieJar *jar, GUri *first_party, SoupCookie *cookie)
 {
        g_return_if_fail (first_party != NULL);
 
@@ -718,7 +724,7 @@ soup_cookie_jar_add_cookie_with_first_party (SoupCookieJar *jar, SoupURI *first_
  * Since: 2.24
  **/
 void
-soup_cookie_jar_set_cookie (SoupCookieJar *jar, SoupURI *uri,
+soup_cookie_jar_set_cookie (SoupCookieJar *jar, GUri *uri,
                            const char *cookie)
 {
        SoupCookie *soup_cookie;
@@ -728,7 +734,7 @@ soup_cookie_jar_set_cookie (SoupCookieJar *jar, SoupURI *uri,
        g_return_if_fail (uri != NULL);
        g_return_if_fail (cookie != NULL);
 
-       if (!uri->host)
+       if (!g_uri_get_host (uri))
                return;
 
        priv = soup_cookie_jar_get_instance_private (jar);
@@ -761,8 +767,8 @@ soup_cookie_jar_set_cookie (SoupCookieJar *jar, SoupURI *uri,
  **/
 void
 soup_cookie_jar_set_cookie_with_first_party (SoupCookieJar *jar,
-                                            SoupURI *uri,
-                                            SoupURI *first_party,
+                                            GUri *uri,
+                                            GUri *first_party,
                                             const char *cookie)
 {
        SoupCookie *soup_cookie;
@@ -772,7 +778,7 @@ soup_cookie_jar_set_cookie_with_first_party (SoupCookieJar *jar,
        g_return_if_fail (first_party != NULL);
        g_return_if_fail (cookie != NULL);
 
-       if (!uri->host)
+       if (!g_uri_get_host (uri))
                return;
 
        soup_cookie = soup_cookie_parse (cookie, uri);
@@ -787,7 +793,7 @@ process_set_cookie_header (SoupMessage *msg, gpointer user_data)
        SoupCookieJar *jar = user_data;
        SoupCookieJarPrivate *priv = soup_cookie_jar_get_instance_private (jar);
        GSList *new_cookies, *nc;
-       SoupURI *first_party, *uri;
+       GUri *first_party, *uri;
 
        if (priv->accept_policy == SOUP_COOKIE_JAR_ACCEPT_NEVER)
                return;
@@ -945,7 +951,7 @@ soup_cookie_jar_delete_cookie (SoupCookieJar *jar,
  * is loaded from that page reject any cookie that it could try to
  * set. For libsoup to be able to tell apart first party cookies from
  * the rest, the application must call soup_message_set_first_party()
- * on each outgoing #SoupMessage, setting the #SoupURI of the main
+ * on each outgoing #SoupMessage, setting the #GUri of the main
  * document. If no first party is set in a message when this policy is
  * in effect, cookies will be assumed to be third party by default.
  * @SOUP_COOKIE_JAR_ACCEPT_GRANDFATHERED_THIRD_PARTY: accept all cookies
@@ -958,7 +964,7 @@ soup_cookie_jar_delete_cookie (SoupCookieJar *jar,
  * set unless it already has a cookie in the cookie jar. For libsoup to
  * be able to tell apart first party cookies from the rest, the
  * application must call soup_message_set_first_party() on each outgoing
- * #SoupMessage, setting the #SoupURI of the main document. If no first
+ * #SoupMessage, setting the #GUri of the main document. If no first
  * party is set in a message when this policy is in effect, cookies will
  * be assumed to be third party by default. Since 2.72.
  *
diff --git a/libsoup/cookies/soup-cookie-jar.h b/libsoup/cookies/soup-cookie-jar.h
index 32c0a15e..2ed912ab 100644
--- a/libsoup/cookies/soup-cookie-jar.h
+++ b/libsoup/cookies/soup-cookie-jar.h
@@ -42,42 +42,42 @@ SOUP_AVAILABLE_IN_2_24
 SoupCookieJar *           soup_cookie_jar_new                         (void);
 SOUP_AVAILABLE_IN_2_24
 char          *           soup_cookie_jar_get_cookies                 (SoupCookieJar             *jar,
-                                                                      SoupURI                   *uri,
+                                                                      GUri                      *uri,
                                                                       gboolean                   for_http);
 SOUP_AVAILABLE_IN_2_40
 GSList        *           soup_cookie_jar_get_cookie_list             (SoupCookieJar             *jar,
-                                                                      SoupURI                   *uri,
+                                                                      GUri                      *uri,
                                                                       gboolean                   for_http);
 SOUP_AVAILABLE_IN_2_70
 GSList        *           soup_cookie_jar_get_cookie_list_with_same_site_info (
                                                                       SoupCookieJar             *jar,
-                                                                      SoupURI                   *uri,
-                                                                      SoupURI                   *top_level,
-                                                                      SoupURI                   
*site_for_cookies,
+                                                                      GUri                      *uri,
+                                                                      GUri                      *top_level,
+                                                                      GUri                      
*site_for_cookies,
                                                                       gboolean                   for_http,
                                                                       gboolean                   
is_safe_method,
                                                                       gboolean                   
is_top_level_navigation);
 SOUP_AVAILABLE_IN_2_24
 void                      soup_cookie_jar_set_cookie                  (SoupCookieJar             *jar,
-                                                                      SoupURI                   *uri,
+                                                                      GUri                      *uri,
                                                                       const char                *cookie);
 SOUP_AVAILABLE_IN_2_30
 void                      soup_cookie_jar_set_cookie_with_first_party (SoupCookieJar             *jar,
-                                                                      SoupURI                   *uri,
-                                                                      SoupURI                   *first_party,
+                                                                      GUri                      *uri,
+                                                                      GUri                      *first_party,
                                                                       const char                *cookie);
 SOUP_AVAILABLE_IN_2_26
 void                      soup_cookie_jar_add_cookie                  (SoupCookieJar             *jar,
                                                                       SoupCookie                *cookie);
 SOUP_AVAILABLE_IN_2_40
 void                      soup_cookie_jar_add_cookie_with_first_party (SoupCookieJar             *jar,
-                                                                      SoupURI                   *first_party,
+                                                                      GUri                      *first_party,
                                                                       SoupCookie                *cookie);
 SOUP_AVAILABLE_IN_2_68
 void                      soup_cookie_jar_add_cookie_full             (SoupCookieJar             *jar,
                                                                        SoupCookie                *cookie,
-                                                                      SoupURI                   *uri,
-                                                                      SoupURI                   
*first_party);
+                                                                      GUri                      *uri,
+                                                                      GUri                      
*first_party);
 SOUP_AVAILABLE_IN_2_26
 void                      soup_cookie_jar_delete_cookie               (SoupCookieJar             *jar,
                                                                       SoupCookie                *cookie);
diff --git a/libsoup/cookies/soup-cookie.c b/libsoup/cookies/soup-cookie.c
index 71540bd8..c8ff41d2 100644
--- a/libsoup/cookies/soup-cookie.c
+++ b/libsoup/cookies/soup-cookie.c
@@ -171,13 +171,13 @@ parse_date (const char **val_p)
 }
 
 static SoupCookie *
-parse_one_cookie (const char *header, SoupURI *origin)
+parse_one_cookie (const char *header, GUri *origin)
 {
        const char *start, *end, *p;
        gboolean has_value;
        SoupCookie *cookie;     
 
-       g_return_val_if_fail (origin == NULL || origin->host, NULL);
+       g_return_val_if_fail (origin == NULL || g_uri_get_host (origin), NULL);
 
        cookie = g_slice_new0 (SoupCookie);
 
@@ -285,14 +285,16 @@ parse_one_cookie (const char *header, SoupURI *origin)
        }
 
        if (origin) {
+                GUri *normalized_origin = soup_normalize_uri (origin);
                /* Sanity-check domain */
                if (cookie->domain) {
-                       if (!soup_cookie_domain_matches (cookie, origin->host)) {
+                       if (!soup_cookie_domain_matches (cookie, g_uri_get_host (normalized_origin))) {
                                soup_cookie_free (cookie);
+                                g_uri_unref (normalized_origin);
                                return NULL;
                        }
                } else
-                       cookie->domain = g_strdup (origin->host);
+                       cookie->domain = g_strdup (g_uri_get_host (normalized_origin));
 
                /* The original cookie spec didn't say that pages
                 * could only set cookies for paths they were under.
@@ -304,15 +306,18 @@ parse_one_cookie (const char *header, SoupURI *origin)
 
                if (!cookie->path) {
                        char *slash;
+                        const char *origin_path = g_uri_get_path (normalized_origin);
 
-                       slash = strrchr (origin->path, '/');
-                       if (!slash || slash == origin->path)
+                       slash = strrchr (origin_path, '/');
+                       if (!slash || slash == origin_path)
                                cookie->path = g_strdup ("/");
                        else {
-                               cookie->path = g_strndup (origin->path,
-                                                         slash - origin->path);
+                               cookie->path = g_strndup (origin_path,
+                                                         slash - origin_path);
                        }
                }
+
+                g_uri_unref (normalized_origin);
        } else if (!cookie->path) {
                cookie->path = g_strdup ("/");
        }
@@ -409,7 +414,7 @@ soup_cookie_new (const char *name, const char *value,
  * Since: 2.24
  **/
 SoupCookie *
-soup_cookie_parse (const char *cookie, SoupURI *origin)
+soup_cookie_parse (const char *cookie, GUri *origin)
 {
        return parse_one_cookie (cookie, origin);
 }
@@ -899,7 +904,7 @@ soup_cookie_free (SoupCookie *cookie)
 GSList *
 soup_cookies_from_response (SoupMessage *msg)
 {
-       SoupURI *origin;
+       GUri *origin;
        const char *name, *value;
        SoupCookie *cookie;
        GSList *cookies = NULL;
@@ -1068,7 +1073,7 @@ soup_cookies_to_cookie_header (GSList *cookies)
 /**
  * soup_cookie_applies_to_uri:
  * @cookie: a #SoupCookie
- * @uri: a #SoupURI
+ * @uri: a #GUri
  *
  * Tests if @cookie should be sent to @uri.
  *
@@ -1082,7 +1087,7 @@ soup_cookies_to_cookie_header (GSList *cookies)
  * Since: 2.24
  **/
 gboolean
-soup_cookie_applies_to_uri (SoupCookie *cookie, SoupURI *uri)
+soup_cookie_applies_to_uri (SoupCookie *cookie, GUri *uri)
 {
        int plen;
 
@@ -1092,18 +1097,20 @@ soup_cookie_applies_to_uri (SoupCookie *cookie, SoupURI *uri)
        if (cookie->expires && soup_date_time_is_past (cookie->expires))
                return FALSE;
 
-       /* uri->path is required to be non-NULL */
-       g_return_val_if_fail (uri->path != NULL, FALSE);
-
        plen = strlen (cookie->path);
        if (plen == 0)
                return TRUE;
-       if (strncmp (cookie->path, uri->path, plen) != 0)
-               return FALSE;
-       if (cookie->path[plen - 1] != '/' &&
-           uri->path[plen] && uri->path[plen] != '/')
-               return FALSE;
 
+        GUri *normalized_uri = soup_normalize_uri (uri);
+        const char *uri_path = g_uri_get_path (normalized_uri);
+       if (strncmp (cookie->path, uri_path, plen) != 0 ||
+           (cookie->path[plen - 1] != '/' && uri_path[plen] &&
+             uri_path[plen] != '/')) {
+                     g_uri_unref (normalized_uri);
+                     return FALSE;
+             }
+
+        g_uri_unref (normalized_uri);
        return TRUE;
 }
 
diff --git a/libsoup/cookies/soup-cookie.h b/libsoup/cookies/soup-cookie.h
index 7f514d1f..dea9a276 100644
--- a/libsoup/cookies/soup-cookie.h
+++ b/libsoup/cookies/soup-cookie.h
@@ -50,7 +50,7 @@ SoupCookie *soup_cookie_new                     (const char  *name,
                                                 int          max_age);
 SOUP_AVAILABLE_IN_2_24
 SoupCookie *soup_cookie_parse                   (const char  *header,
-                                                SoupURI     *origin);
+                                                GUri        *origin);
 SOUP_AVAILABLE_IN_2_24
 SoupCookie *soup_cookie_copy                    (SoupCookie  *cookie);
 
@@ -106,7 +106,7 @@ char       *soup_cookie_to_cookie_header        (SoupCookie  *cookie);
 
 SOUP_AVAILABLE_IN_2_24
 gboolean    soup_cookie_applies_to_uri          (SoupCookie  *cookie,
-                                                SoupURI     *uri);
+                                                GUri        *uri);
 SOUP_AVAILABLE_IN_2_24
 gboolean    soup_cookie_equal                   (SoupCookie  *cookie1,
                                                 SoupCookie  *cookie2);
diff --git a/libsoup/hsts/soup-hsts-enforcer.c b/libsoup/hsts/soup-hsts-enforcer.c
index 9201f3c6..830e987e 100644
--- a/libsoup/hsts/soup-hsts-enforcer.c
+++ b/libsoup/hsts/soup-hsts-enforcer.c
@@ -461,7 +461,7 @@ soup_hsts_enforcer_process_sts_header (SoupHSTSEnforcer *hsts_enforcer,
                                       SoupMessage *msg)
 {
        SoupHSTSPolicy *policy;
-       SoupURI *uri;
+       GUri *uri;
 
        uri = soup_message_get_uri (msg);
 
@@ -482,24 +482,39 @@ got_sts_header_cb (SoupMessage *msg, gpointer user_data)
        soup_hsts_enforcer_process_sts_header (hsts_enforcer, msg);
 }
 
+static GUri *
+copy_uri_with_new_scheme (GUri *uri, const char *scheme, int port)
+{
+        return g_uri_build_with_user (
+                g_uri_get_flags (uri),
+                scheme,
+                g_uri_get_user (uri),
+                g_uri_get_password (uri),
+                g_uri_get_auth_params (uri),
+                g_uri_get_host (uri),
+                port,
+                g_uri_get_path (uri),
+                g_uri_get_query (uri),
+                g_uri_get_fragment (uri)
+        );
+}
+
 static void
 rewrite_message_uri_to_https (SoupMessage *msg)
 {
-       SoupURI *uri;
-       guint original_port;
+       GUri *uri, *new_uri;
+       int port;
 
-       uri = soup_uri_copy (soup_message_get_uri (msg));
-
-       original_port = soup_uri_get_port (uri);
-       /* This will unconditionally rewrite the port to 443. */
-       soup_uri_set_scheme (uri, SOUP_URI_SCHEME_HTTPS);
+       uri = soup_message_get_uri (msg);
+       port = soup_uri_get_port_with_default (uri);
        /* From the RFC: "If the URI contains an explicit port component that
           is not equal to "80", the port component value MUST be preserved;" */
-       if (original_port != 80)
-               soup_uri_set_port (uri, original_port);
+       if (port == 80)
+                port = 443;
 
-       soup_message_set_uri (msg, uri);
-       soup_uri_free (uri);
+        new_uri = copy_uri_with_new_scheme (uri, "https", port);
+       soup_message_set_uri (msg, new_uri);
+       g_uri_unref (new_uri);
 }
 
 static void
@@ -520,19 +535,17 @@ on_sts_known_host_message_starting (SoupMessage *msg, SoupHSTSEnforcer *hsts_enf
 static void
 preprocess_request (SoupHSTSEnforcer *enforcer, SoupMessage *msg)
 {
-       SoupURI *uri;
-       const char *scheme;
+       GUri *uri;
        const char *host;
        char *canonicalized = NULL;
 
        uri = soup_message_get_uri (msg);
-       host = soup_uri_get_host (uri);
+       host = g_uri_get_host (uri);
 
        if (g_hostname_is_ip_address (host))
                return;
 
-       scheme = soup_uri_get_scheme (uri);
-       if (scheme == SOUP_URI_SCHEME_HTTP) {
+       if (soup_uri_is_http (uri, NULL)) {
                if (g_hostname_is_ascii_encoded (host)) {
                        canonicalized = g_hostname_to_unicode (host);
                        if (!canonicalized)
@@ -546,7 +559,7 @@ preprocess_request (SoupHSTSEnforcer *enforcer, SoupMessage *msg)
                        g_signal_emit (enforcer, signals[HSTS_ENFORCED], 0, msg);
                }
                g_free (canonicalized);
-       } else if (scheme == SOUP_URI_SCHEME_HTTPS) {
+       } else if (soup_uri_is_https (uri, NULL)) {
                soup_message_add_header_handler (msg, "got-headers",
                                                 "Strict-Transport-Security",
                                                 G_CALLBACK (got_sts_header_cb),
diff --git a/libsoup/hsts/soup-hsts-enforcer.h b/libsoup/hsts/soup-hsts-enforcer.h
index d0223188..32f3ab40 100644
--- a/libsoup/hsts/soup-hsts-enforcer.h
+++ b/libsoup/hsts/soup-hsts-enforcer.h
@@ -21,7 +21,7 @@ G_DECLARE_DERIVABLE_TYPE (SoupHSTSEnforcer, soup_hsts_enforcer, SOUP, HSTS_ENFOR
  * whether changes made to it will be lost when the underlying #SoupSession is finished.
  * @has_valid_policy: The @has_valid_policy function is called to check whether there is a valid
  * policy for the given domain. This method should return %TRUE for #SoupHSTSEnforcer to
- * change the scheme of the #SoupURI in the #SoupMessage to HTTPS. Implementations might want to
+ * change the scheme of the #GUri in the #SoupMessage to HTTPS. Implementations might want to
  * chain up to the @has_valid_policy in the parent class to check, for instance, for runtime
  * policies.
  * @changed: The class closure for the #SoupHSTSEnforcer::changed signal.
diff --git a/libsoup/hsts/soup-hsts-policy.c b/libsoup/hsts/soup-hsts-policy.c
index 6a8bceae..86f7c31b 100644
--- a/libsoup/hsts/soup-hsts-policy.c
+++ b/libsoup/hsts/soup-hsts-policy.c
@@ -271,7 +271,7 @@ soup_hsts_policy_new_from_response (SoupMessage *msg)
 
        soup_message_headers_iter_init (&iter, msg->response_headers);
        while (soup_message_headers_iter_next (&iter, &name, &value)) {
-               SoupURI *uri;
+               GUri *uri;
                GHashTable *params;
                const char *max_age_str;
                char *endptr;
@@ -304,7 +304,7 @@ soup_hsts_policy_new_from_response (SoupMessage *msg)
                if (include_subdomains_value)
                        goto out;
 
-               policy = soup_hsts_policy_new (uri->host, max_age, include_subdomains);
+               policy = soup_hsts_policy_new (g_uri_get_host (uri), max_age, include_subdomains);
        out:
                soup_header_free_param_list (params);
                return policy;
diff --git a/libsoup/soup-connection.c b/libsoup/soup-connection.c
index df2cdb59..a50c0aae 100644
--- a/libsoup/soup-connection.c
+++ b/libsoup/soup-connection.c
@@ -19,7 +19,7 @@ typedef struct {
        SoupSocket  *socket;
        SoupSocketProperties *socket_props;
 
-       SoupURI *remote_uri, *proxy_uri;
+       GUri *remote_uri, *proxy_uri;
        gboolean ssl;
 
        SoupMessage *current_msg;
@@ -67,8 +67,8 @@ soup_connection_finalize (GObject *object)
 {
        SoupConnectionPrivate *priv = soup_connection_get_instance_private (SOUP_CONNECTION (object));
 
-       g_clear_pointer (&priv->remote_uri, soup_uri_free);
-       g_clear_pointer (&priv->proxy_uri, soup_uri_free);
+       g_clear_pointer (&priv->remote_uri, g_uri_unref);
+       g_clear_pointer (&priv->proxy_uri, g_uri_unref);
        g_clear_pointer (&priv->socket_props, soup_socket_properties_unref);
        g_clear_object (&priv->current_msg);
 
@@ -178,7 +178,7 @@ soup_connection_class_init (SoupConnectionClass *connection_class)
                g_param_spec_boxed (SOUP_CONNECTION_REMOTE_URI,
                                    "Remote URI",
                                    "The URI of the HTTP server",
-                                   SOUP_TYPE_URI,
+                                   G_TYPE_URI,
                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                                    G_PARAM_STATIC_STRINGS));
        g_object_class_install_property (
@@ -263,7 +263,7 @@ current_msg_got_body (SoupMessage *msg, gpointer user_data)
                soup_connection_event (conn, G_SOCKET_CLIENT_PROXY_NEGOTIATED, NULL);
 
                /* We're now effectively no longer proxying */
-               g_clear_pointer (&priv->proxy_uri, soup_uri_free);
+               g_clear_pointer (&priv->proxy_uri, g_uri_unref);
        }
 
        priv->reusable = soup_message_is_keepalive (msg);
@@ -402,9 +402,9 @@ soup_connection_connect_async (SoupConnection      *conn,
        /* Set the protocol to ensure correct proxy resolution. */
        remote_addr =
                g_object_new (G_TYPE_NETWORK_ADDRESS,
-                             "hostname", priv->remote_uri->host,
-                             "port", priv->remote_uri->port,
-                             "scheme", priv->remote_uri->scheme,
+                             "hostname", g_uri_get_host (priv->remote_uri),
+                             "port", soup_uri_get_port_with_default (priv->remote_uri),
+                             "scheme", g_uri_get_scheme (priv->remote_uri),
                              NULL);
 
        priv->socket =
@@ -447,9 +447,9 @@ soup_connection_connect_sync (SoupConnection  *conn,
        /* Set the protocol to ensure correct proxy resolution. */
        remote_addr =
                g_object_new (G_TYPE_NETWORK_ADDRESS,
-                             "hostname", priv->remote_uri->host,
-                             "port", priv->remote_uri->port,
-                             "scheme", priv->remote_uri->scheme,
+                             "hostname", g_uri_get_host (priv->remote_uri),
+                             "port", soup_uri_get_port_with_default (priv->remote_uri),
+                             "scheme", g_uri_get_scheme (priv->remote_uri),
                              NULL);
 
        priv->socket =
@@ -599,7 +599,7 @@ soup_connection_get_socket (SoupConnection *conn)
        return priv->socket;
 }
 
-SoupURI *
+GUri *
 soup_connection_get_remote_uri (SoupConnection *conn)
 {
        SoupConnectionPrivate *priv = soup_connection_get_instance_private (conn);
@@ -609,7 +609,7 @@ soup_connection_get_remote_uri (SoupConnection *conn)
        return priv->remote_uri;
 }
 
-SoupURI *
+GUri *
 soup_connection_get_proxy_uri (SoupConnection *conn)
 {
        SoupConnectionPrivate *priv = soup_connection_get_instance_private (conn);
diff --git a/libsoup/soup-connection.h b/libsoup/soup-connection.h
index 19888f1f..2f5065d5 100644
--- a/libsoup/soup-connection.h
+++ b/libsoup/soup-connection.h
@@ -60,8 +60,8 @@ gboolean        soup_connection_start_ssl_finish (SoupConnection       *conn,
 void            soup_connection_disconnect     (SoupConnection   *conn);
 
 SoupSocket     *soup_connection_get_socket     (SoupConnection   *conn);
-SoupURI        *soup_connection_get_remote_uri (SoupConnection   *conn);
-SoupURI        *soup_connection_get_proxy_uri  (SoupConnection   *conn);
+GUri           *soup_connection_get_remote_uri (SoupConnection   *conn);
+GUri           *soup_connection_get_proxy_uri  (SoupConnection   *conn);
 gboolean        soup_connection_is_via_proxy   (SoupConnection   *conn);
 gboolean        soup_connection_is_tunnelled   (SoupConnection   *conn);
 
diff --git a/libsoup/soup-directory-input-stream.c b/libsoup/soup-directory-input-stream.c
index 5c24883f..68af506f 100644
--- a/libsoup/soup-directory-input-stream.c
+++ b/libsoup/soup-directory-input-stream.c
@@ -241,7 +241,7 @@ soup_directory_input_stream_setup_buffer (SoupDirectoryInputStream *stream)
 
 GInputStream *
 soup_directory_input_stream_new (GFileEnumerator *enumerator,
-                                SoupURI         *uri)
+                                GUri            *uri)
 {
        GInputStream *stream;
 
@@ -251,7 +251,7 @@ soup_directory_input_stream_new (GFileEnumerator *enumerator,
        stream = g_object_new (SOUP_TYPE_DIRECTORY_INPUT_STREAM, NULL);
 
        SOUP_DIRECTORY_INPUT_STREAM (stream)->enumerator = g_object_ref (enumerator);
-       SOUP_DIRECTORY_INPUT_STREAM (stream)->uri = soup_uri_to_string (uri, FALSE);
+       SOUP_DIRECTORY_INPUT_STREAM (stream)->uri = g_uri_to_string (uri);
 
        soup_directory_input_stream_setup_buffer (SOUP_DIRECTORY_INPUT_STREAM (stream));
 
diff --git a/libsoup/soup-directory-input-stream.h b/libsoup/soup-directory-input-stream.h
index 1ffb84eb..9ed92b08 100644
--- a/libsoup/soup-directory-input-stream.h
+++ b/libsoup/soup-directory-input-stream.h
@@ -54,7 +54,7 @@ struct _SoupDirectoryInputStreamClass {
 GType         soup_directory_input_stream_get_type (void);
 
 GInputStream *soup_directory_input_stream_new      (GFileEnumerator *enumerator,
-                                                   SoupURI         *uri);
+                                                   GUri            *uri);
 
 
 G_END_DECLS
diff --git a/libsoup/soup-form.c b/libsoup/soup-form.c
index 32e7de3c..f85c8f49 100644
--- a/libsoup/soup-form.c
+++ b/libsoup/soup-form.c
@@ -355,22 +355,38 @@ soup_form_encode_valist (const char *first_field, va_list args)
        return g_string_free (str, FALSE);
 }
 
+static GUri *
+copy_uri_with_new_query (GUri *uri, const char *query)
+{
+        return g_uri_build_with_user (
+                g_uri_get_flags (uri),
+                g_uri_get_scheme (uri),
+                g_uri_get_user (uri),
+                g_uri_get_password (uri),
+                g_uri_get_auth_params (uri),
+                g_uri_get_host (uri),
+                g_uri_get_port (uri),
+                g_uri_get_path (uri),
+                query,
+                g_uri_get_fragment (uri)
+        );
+}
+
 static SoupMessage *
 soup_form_request_for_data (const char *method, const char *uri_string,
                            char *form_data)
 {
        SoupMessage *msg;
-       SoupURI *uri;
+       GUri *uri;
 
-       uri = soup_uri_new (uri_string);
+       uri = soup_uri_parse_normalized (NULL, uri_string, NULL);
        if (!uri)
                return NULL;
 
        if (!strcmp (method, "GET")) {
-               g_free (uri->query);
-               uri->query = form_data;
-
-               msg = soup_message_new_from_uri (method, uri);
+                GUri *new_uri = copy_uri_with_new_query (uri, form_data);
+               msg = soup_message_new_from_uri (method, new_uri);
+                g_uri_unref (new_uri);
        } else if (!strcmp (method, "POST") || !strcmp (method, "PUT")) {
                GBytes *body;
 
@@ -386,7 +402,7 @@ soup_form_request_for_data (const char *method, const char *uri_string,
                /* Don't crash */
                msg = soup_message_new_from_uri (method, uri);
        }
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        return msg;
 }
diff --git a/libsoup/soup-headers.c b/libsoup/soup-headers.c
index fbe1e986..e97390f6 100644
--- a/libsoup/soup-headers.c
+++ b/libsoup/soup-headers.c
@@ -694,7 +694,7 @@ decode_rfc5987 (char *encoded_string)
        if (!q)
                return FALSE;
 
-       decoded = soup_uri_decode (q + 1);
+       decoded = g_uri_unescape_string (q + 1, NULL);
        if (iso_8859_1) {
                char *utf8 =  g_convert_with_fallback (decoded, -1, "UTF-8",
                                                       "iso-8859-1", "_",
@@ -908,7 +908,7 @@ append_param_rfc5987 (GString    *string,
 
        g_string_append (string, name);
        g_string_append (string, "*=UTF-8''");
-       encoded = soup_uri_encode (value, " *'%()<>@,;:\\\"/[]?=");
+       encoded = g_uri_escape_string (value, "*'%()<>@,;:\\\"/[]?=", FALSE);
        g_string_append (string, encoded);
        g_free (encoded);
 }
diff --git a/libsoup/soup-logger.c b/libsoup/soup-logger.c
index d76701a2..01019aef 100644
--- a/libsoup/soup-logger.c
+++ b/libsoup/soup-logger.c
@@ -520,7 +520,7 @@ print_request (SoupLogger *logger, SoupMessage *msg,
        SoupMessageHeadersIter iter;
        const char *name, *value;
        char *socket_dbg;
-       SoupURI *uri;
+       GUri *uri;
 
        if (priv->request_filter) {
                log_level = priv->request_filter (logger, msg,
@@ -535,14 +535,14 @@ print_request (SoupLogger *logger, SoupMessage *msg,
        if (msg->method == SOUP_METHOD_CONNECT) {
                soup_logger_print (logger, SOUP_LOGGER_LOG_MINIMAL, '>',
                                   "CONNECT %s:%u HTTP/1.%d",
-                                  uri->host, uri->port,
+                                  g_uri_get_host (uri), g_uri_get_port (uri),
                                   soup_message_get_http_version (msg));
        } else {
                soup_logger_print (logger, SOUP_LOGGER_LOG_MINIMAL, '>',
                                   "%s %s%s%s HTTP/1.%d",
-                                  msg->method, uri->path,
-                                  uri->query ? "?" : "",
-                                  uri->query ? uri->query : "",
+                                  msg->method, g_uri_get_path (uri),
+                                  g_uri_get_query (uri) ? "?" : "",
+                                  g_uri_get_query (uri) ? g_uri_get_query (uri) : "",
                                   soup_message_get_http_version (msg));
        }
 
@@ -570,21 +570,19 @@ print_request (SoupLogger *logger, SoupMessage *msg,
                return;
 
        if (!soup_message_headers_get_one (msg->request_headers, "Host")) {
-               char *uri_host;
+               char *uri_host = (char*)g_uri_get_host (uri);
 
-               if (strchr (uri->host, ':'))
-                       uri_host = g_strdup_printf ("[%s]", uri->host);
-               else if (g_hostname_is_non_ascii (uri->host))
-                       uri_host = g_hostname_to_ascii (uri->host);
-               else
-                       uri_host = uri->host;
+               if (strchr (uri_host, ':'))
+                       uri_host = g_strdup_printf ("[%s]", uri_host);
+               else if (g_hostname_is_non_ascii (uri_host))
+                       uri_host = g_hostname_to_ascii (uri_host);
 
                soup_logger_print (logger, SOUP_LOGGER_LOG_HEADERS, '>',
                                   "Host: %s%c%u", uri_host,
                                   soup_uri_uses_default_port (uri) ? '\0' : ':',
-                                  uri->port);
+                                  g_uri_get_port (uri));
 
-               if (uri_host != uri->host)
+               if (uri_host != g_uri_get_host (uri))
                        g_free (uri_host);
        }
        soup_message_headers_iter_init (&iter, msg->request_headers);
diff --git a/libsoup/soup-message-client-io.c b/libsoup/soup-message-client-io.c
index fdaa79dc..9befded9 100644
--- a/libsoup/soup-message-client-io.c
+++ b/libsoup/soup-message-client-io.c
@@ -72,31 +72,33 @@ get_request_headers (SoupMessage *msg, GString *header,
                     SoupEncoding *encoding, gpointer user_data)
 {
        SoupMessageQueueItem *item = user_data;
-       SoupURI *uri = soup_message_get_uri (msg);
+       GUri *uri = soup_message_get_uri (msg);
        char *uri_host;
        char *uri_string;
        SoupMessageHeadersIter iter;
        const char *name, *value;
 
-       if (strchr (uri->host, ':'))
-               uri_host = g_strdup_printf ("[%.*s]", (int) strcspn (uri->host, "%"), uri->host);
-       else if (g_hostname_is_non_ascii (uri->host))
-               uri_host = g_hostname_to_ascii (uri->host);
-       else
-               uri_host = uri->host;
+        uri_host = (char*)g_uri_get_host (uri);
+       if (strchr (uri_host, ':'))
+               uri_host = g_strdup_printf ("[%.*s]", (int) strcspn (uri_host, "%"), uri_host);
+       else if (g_hostname_is_non_ascii (uri_host))
+               uri_host = g_hostname_to_ascii (uri_host);
 
        if (msg->method == SOUP_METHOD_CONNECT) {
                /* CONNECT URI is hostname:port for tunnel destination */
-               uri_string = g_strdup_printf ("%s:%d", uri_host, uri->port);
+               uri_string = g_strdup_printf ("%s:%d", uri_host, g_uri_get_port (uri));
        } else {
                gboolean proxy = soup_connection_is_via_proxy (item->conn);
 
                /* Proxy expects full URI to destination. Otherwise
                 * just the path.
                 */
-               uri_string = soup_uri_to_string (uri, !proxy);
+                if (!proxy)
+                        uri_string = soup_uri_get_path_and_query (uri);
+                else
+                        uri_string = g_uri_to_string (uri);
 
-               if (proxy && uri->fragment) {
+               if (proxy && g_uri_get_fragment (uri)) {
                        /* Strip fragment */
                        char *fragment = strchr (uri_string, '#');
                        if (fragment)
@@ -114,11 +116,11 @@ get_request_headers (SoupMessage *msg, GString *header,
                                                uri_host);
                } else {
                        g_string_append_printf (header, "Host: %s:%d\r\n",
-                                               uri_host, uri->port);
+                                               uri_host, g_uri_get_port (uri));
                }
        }
        g_free (uri_string);
-       if (uri_host != uri->host)
+       if (uri_host != g_uri_get_host (uri))
                g_free (uri_host);
 
        *encoding = soup_message_headers_get_encoding (msg->request_headers);
diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c
index cfbba0f7..cb4eb5db 100644
--- a/libsoup/soup-message-io.c
+++ b/libsoup/soup-message-io.c
@@ -1083,8 +1083,8 @@ io_run_until (SoupMessage *msg, gboolean blocking,
        /* Allow profiling of network requests. */
        if (io->read_state == SOUP_MESSAGE_IO_STATE_DONE &&
            io->write_state == SOUP_MESSAGE_IO_STATE_DONE) {
-               SoupURI *uri = soup_message_get_uri (msg);
-               char *uri_str = soup_uri_to_string (uri, FALSE);
+               GUri *uri = soup_message_get_uri (msg);
+               char *uri_str = g_uri_to_string_partial (uri, G_URI_HIDE_PASSWORD);
                const gchar *last_modified = soup_message_headers_get_one (msg->request_headers, 
"Last-Modified");
                const gchar *etag = soup_message_headers_get_one (msg->request_headers, "ETag");
 
diff --git a/libsoup/soup-message-private.h b/libsoup/soup-message-private.h
index 06bd1151..8fc64d79 100644
--- a/libsoup/soup-message-private.h
+++ b/libsoup/soup-message-private.h
@@ -23,15 +23,15 @@ typedef struct {
 
        SoupHTTPVersion    http_version, orig_http_version;
 
-       SoupURI           *uri;
+       GUri              *uri;
 
        SoupAuth          *auth, *proxy_auth;
        SoupConnection    *connection;
 
        GHashTable        *disabled_features;
 
-       SoupURI           *first_party;
-       SoupURI           *site_for_cookies;
+       GUri              *first_party;
+       GUri              *site_for_cookies;
 
        GTlsCertificate      *tls_certificate;
        GTlsCertificateFlags  tls_errors;
diff --git a/libsoup/soup-message-server-io.c b/libsoup/soup-message-server-io.c
index acd1490c..568aae14 100644
--- a/libsoup/soup-message-server-io.c
+++ b/libsoup/soup-message-server-io.c
@@ -19,24 +19,29 @@
 #include "soup-misc.h"
 #include "soup-socket-private.h"
 
-static SoupURI *
+static GUri *
 parse_connect_authority (const char *req_path)
 {
-       SoupURI *uri;
+       GUri *uri;
        char *fake_uri;
 
        fake_uri = g_strdup_printf ("http://%s";, req_path);
-       uri = soup_uri_new (fake_uri);
+       uri = soup_uri_parse_normalized (NULL, fake_uri, NULL);
        g_free (fake_uri);
 
-       if (uri->user || uri->password ||
-           uri->query || uri->fragment ||
-           !uri->host ||
-           (uri->port == 0) ||
-           (strcmp (uri->path, "/") != 0)) {
-               soup_uri_free (uri);
-               return NULL;
-       }
+        if (!uri)
+                return NULL;
+
+        if (g_uri_get_user (uri) ||
+            g_uri_get_password (uri) ||
+            g_uri_get_query (uri) ||
+            g_uri_get_fragment (uri) ||
+            !g_uri_get_host (uri) ||
+            g_uri_get_port (uri) <= 0 ||
+            strcmp (g_uri_get_path (uri), "/") != 0) {
+                g_uri_unref (uri);
+                return NULL;
+        }
 
        return uri;
 }
@@ -45,11 +50,12 @@ static guint
 parse_request_headers (SoupMessage *msg, char *headers, guint headers_len,
                       SoupEncoding *encoding, gpointer sock, GError **error)
 {
-       char *req_method, *req_path, *url;
+       char *req_method, *req_path;
        SoupHTTPVersion version;
        const char *req_host;
        guint status;
-       SoupURI *uri;
+        char *url;
+       GUri *uri;
 
        status = soup_headers_parse_request (headers, headers_len,
                                             msg->request_headers,
@@ -89,52 +95,51 @@ parse_request_headers (SoupMessage *msg, char *headers, guint headers_len,
 
        if (!strcmp (req_path, "*") && req_host) {
                /* Eg, "OPTIONS * HTTP/1.1" */
-               url = g_strdup_printf ("%s://%s",
+               url = g_strdup_printf ("%s://%s/*",
                                       soup_socket_is_ssl (sock) ? "https" : "http",
                                       req_host);
-               uri = soup_uri_new (url);
-               if (uri)
-                       soup_uri_set_path (uri, "*");
+               uri = g_uri_parse (url, SOUP_HTTP_URI_FLAGS, NULL);
                g_free (url);
        } else if (msg->method == SOUP_METHOD_CONNECT) {
                /* Authority */
                uri = parse_connect_authority (req_path);
        } else if (*req_path != '/') {
                /* Absolute URI */
-               uri = soup_uri_new (req_path);
+               uri = g_uri_parse (req_path, SOUP_HTTP_URI_FLAGS, NULL);
        } else if (req_host) {
                url = g_strdup_printf ("%s://%s%s",
                                       soup_socket_is_ssl (sock) ? "https" : "http",
                                       req_host, req_path);
-               uri = soup_uri_new (url);
+               uri = g_uri_parse (url, SOUP_HTTP_URI_FLAGS, NULL);
                g_free (url);
        } else if (soup_message_get_http_version (msg) == SOUP_HTTP_1_0) {
                /* No Host header, no AbsoluteUri */
                GInetSocketAddress *addr = soup_socket_get_local_address (sock);
                 GInetAddress *inet_addr = g_inet_socket_address_get_address (addr);
                 char *local_ip = g_inet_address_to_string (inet_addr);
+                int port = g_inet_socket_address_get_port (addr);
+                if (port == 0)
+                        port = -1;
 
-               uri = soup_uri_new (NULL);
-               soup_uri_set_scheme (uri, soup_socket_is_ssl (sock) ?
-                                    SOUP_URI_SCHEME_HTTPS :
-                                    SOUP_URI_SCHEME_HTTP);
-               soup_uri_set_host (uri, local_ip);
-               soup_uri_set_port (uri, g_inet_socket_address_get_port (addr));
-               soup_uri_set_path (uri, req_path);
+                uri = g_uri_build (SOUP_HTTP_URI_FLAGS, 
+                                   soup_socket_is_ssl (sock) ? "https" : "http",
+                                   NULL, local_ip, port, req_path, NULL, NULL);
                g_free (local_ip);
        } else
                uri = NULL;
 
        g_free (req_path);
 
-       if (!uri || !uri->host) {
+       if (!uri || !g_uri_get_host (uri)) {
                if (uri)
-                       soup_uri_free (uri);
+                       g_uri_unref (uri);
                return SOUP_STATUS_BAD_REQUEST;
        }
 
-       soup_message_set_uri (msg, uri);
-       soup_uri_free (uri);
+        GUri *normalized_uri = soup_normalize_uri (uri);
+       soup_message_set_uri (msg, normalized_uri);
+       g_uri_unref (uri);
+        g_uri_unref (normalized_uri);
 
        return SOUP_STATUS_OK;
 }
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index 4cbef66b..ebe12d72 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -170,9 +170,9 @@ soup_message_finalize (GObject *object)
 
        soup_message_io_cleanup (msg);
 
-       g_clear_pointer (&priv->uri, soup_uri_free);
-       g_clear_pointer (&priv->first_party, soup_uri_free);
-       g_clear_pointer (&priv->site_for_cookies, soup_uri_free);
+       g_clear_pointer (&priv->uri, g_uri_unref);
+       g_clear_pointer (&priv->first_party, g_uri_unref);
+       g_clear_pointer (&priv->site_for_cookies, g_uri_unref);
 
        g_clear_object (&priv->auth);
        g_clear_object (&priv->proxy_auth);
@@ -705,14 +705,14 @@ soup_message_class_init (SoupMessageClass *message_class)
         * SOUP_MESSAGE_URI:
         *
         * Alias for the #SoupMessage:uri property. (The message's
-        * #SoupURI.)
+        * #GUri.)
         **/
        g_object_class_install_property (
                object_class, PROP_URI,
                g_param_spec_boxed (SOUP_MESSAGE_URI,
                                    "URI",
                                    "The message's Request-URI",
-                                   SOUP_TYPE_URI,
+                                   G_TYPE_URI,
                                    G_PARAM_READWRITE |
                                    G_PARAM_STATIC_STRINGS));
        /**
@@ -791,7 +791,7 @@ soup_message_class_init (SoupMessageClass *message_class)
         * SOUP_MESSAGE_FIRST_PARTY:
         *
         * Alias for the #SoupMessage:first-party property. (The
-        * #SoupURI loaded in the application when the message was
+        * #GUri loaded in the application when the message was
         * queued.)
         *
         * Since: 2.30
@@ -799,7 +799,7 @@ soup_message_class_init (SoupMessageClass *message_class)
        /**
         * SoupMessage:first-party:
         *
-        * The #SoupURI loaded in the application when the message was
+        * The #GUri loaded in the application when the message was
         * queued.
         *
         * Since: 2.30
@@ -809,7 +809,7 @@ soup_message_class_init (SoupMessageClass *message_class)
                g_param_spec_boxed (SOUP_MESSAGE_FIRST_PARTY,
                                    "First party",
                                    "The URI loaded in the application when the message was requested.",
-                                   SOUP_TYPE_URI,
+                                   G_TYPE_URI,
                                    G_PARAM_READWRITE |
                                    G_PARAM_STATIC_STRINGS));
        /**
@@ -824,7 +824,7 @@ soup_message_class_init (SoupMessageClass *message_class)
                g_param_spec_boxed (SOUP_MESSAGE_SITE_FOR_COOKIES,
                                    "Site for cookies",
                                    "The URI for the site to compare cookies against",
-                                   SOUP_TYPE_URI,
+                                   G_TYPE_URI,
                                    G_PARAM_READWRITE));
        /**
         * SoupMessage:is-top-level-navigation:
@@ -1022,35 +1022,35 @@ SoupMessage *
 soup_message_new (const char *method, const char *uri_string)
 {
        SoupMessage *msg;
-       SoupURI *uri;
+       GUri *uri;
 
        g_return_val_if_fail (method != NULL, NULL);
        g_return_val_if_fail (uri_string != NULL, NULL);
 
-       uri = soup_uri_new (uri_string);
+       uri = soup_uri_parse_normalized (NULL, uri_string, NULL);
        if (!uri)
                return NULL;
-       if (!uri->host) {
-               soup_uri_free (uri);
+       if (!g_uri_get_host (uri)) {
+               g_uri_unref (uri);
                return NULL;
        }
 
        msg = soup_message_new_from_uri (method, uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        return msg;
 }
 
 /**
  * soup_message_new_from_uri:
  * @method: the HTTP method for the created request
- * @uri: the destination endpoint (as a #SoupURI)
+ * @uri: the destination endpoint (as a #GUri)
  * 
  * Creates a new empty #SoupMessage, which will connect to @uri
  *
  * Return value: the new #SoupMessage
  */
 SoupMessage *
-soup_message_new_from_uri (const char *method, SoupURI *uri)
+soup_message_new_from_uri (const char *method, GUri *uri)
 {
        return g_object_new (SOUP_TYPE_MESSAGE,
                             SOUP_MESSAGE_METHOD, method,
@@ -1676,14 +1676,14 @@ soup_message_is_keepalive (SoupMessage *msg)
 /**
  * soup_message_set_uri:
  * @msg: a #SoupMessage
- * @uri: the new #SoupURI
+ * @uri: the new #GUri
  *
  * Sets @msg's URI to @uri. If @msg has already been sent and you want
  * to re-send it with the new URI, you need to call
  * soup_session_requeue_message().
  **/
 void
-soup_message_set_uri (SoupMessage *msg, SoupURI *uri)
+soup_message_set_uri (SoupMessage *msg, GUri *uri)
 {
        SoupMessagePrivate *priv;
 
@@ -1691,8 +1691,8 @@ soup_message_set_uri (SoupMessage *msg, SoupURI *uri)
        priv = soup_message_get_instance_private (msg);
 
        if (priv->uri)
-               soup_uri_free (priv->uri);
-       priv->uri = soup_uri_copy (uri);
+               g_uri_unref (priv->uri);
+       priv->uri = soup_normalize_uri (uri);
 
        g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_URI);
 }
@@ -1705,7 +1705,7 @@ soup_message_set_uri (SoupMessage *msg, SoupURI *uri)
  *
  * Return value: (transfer none): the URI @msg is targeted for.
  **/
-SoupURI *
+GUri *
 soup_message_get_uri (SoupMessage *msg)
 {
        SoupMessagePrivate *priv;
@@ -1866,13 +1866,13 @@ soup_message_get_disabled_features (SoupMessage *msg)
  * soup_message_get_first_party:
  * @msg: a #SoupMessage
  *
- * Gets @msg's first-party #SoupURI
+ * Gets @msg's first-party #GUri
  * 
- * Returns: (transfer none): the @msg's first party #SoupURI
+ * Returns: (transfer none): the @msg's first party #GUri
  * 
  * Since: 2.30
  **/
-SoupURI *
+GUri *
 soup_message_get_first_party (SoupMessage *msg)
 {
        SoupMessagePrivate *priv;
@@ -1886,9 +1886,9 @@ soup_message_get_first_party (SoupMessage *msg)
 /**
  * soup_message_set_first_party:
  * @msg: a #SoupMessage
- * @first_party: the #SoupURI for the @msg's first party
+ * @first_party: the #GUri for the @msg's first party
  * 
- * Sets @first_party as the main document #SoupURI for @msg. For
+ * Sets @first_party as the main document #GUri for @msg. For
  * details of when and how this is used refer to the documentation for
  * #SoupCookieJarAcceptPolicy.
  *
@@ -1896,23 +1896,27 @@ soup_message_get_first_party (SoupMessage *msg)
  **/
 void
 soup_message_set_first_party (SoupMessage *msg,
-                             SoupURI     *first_party)
+                             GUri        *first_party)
 {
        SoupMessagePrivate *priv;
+        GUri *normalized_first_party;
 
        g_return_if_fail (SOUP_IS_MESSAGE (msg));
        g_return_if_fail (first_party != NULL);
 
        priv = soup_message_get_instance_private (msg);
+        normalized_first_party = soup_normalize_uri (first_party);
 
        if (priv->first_party) {
-               if (soup_uri_equal (priv->first_party, first_party))
+               if (soup_uri_equal (priv->first_party, normalized_first_party)) {
+                        g_uri_unref (normalized_first_party);
                        return;
+                }
 
-               soup_uri_free (priv->first_party);
+               g_uri_unref (priv->first_party);
        }
 
-       priv->first_party = soup_uri_copy (first_party);
+       priv->first_party = g_steal_pointer (&normalized_first_party);
        g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_FIRST_PARTY);
 }
 
@@ -1920,13 +1924,13 @@ soup_message_set_first_party (SoupMessage *msg,
  * soup_message_get_site_for_cookies:
  * @msg: a #SoupMessage
  *
- * Gets @msg's site for cookies #SoupURI
+ * Gets @msg's site for cookies #GUri
  *
- * Returns: (transfer none): the @msg's site for cookies #SoupURI
+ * Returns: (transfer none): the @msg's site for cookies #GUri
  *
  * Since: 2.70
  **/
-SoupURI *
+GUri *
 soup_message_get_site_for_cookies (SoupMessage *msg)
 {
        SoupMessagePrivate *priv;
@@ -1940,7 +1944,7 @@ soup_message_get_site_for_cookies (SoupMessage *msg)
 /**
  * soup_message_set_site_for_cookies:
  * @msg: a #SoupMessage
- * @site_for_cookies: (nullable): the #SoupURI for the @msg's site for cookies
+ * @site_for_cookies: (nullable): the #GUri for the @msg's site for cookies
  *
  * Sets @site_for_cookies as the policy URL for same-site cookies for @msg.
  *
@@ -1955,9 +1959,10 @@ soup_message_get_site_for_cookies (SoupMessage *msg)
  **/
 void
 soup_message_set_site_for_cookies (SoupMessage *msg,
-                                  SoupURI     *site_for_cookies)
+                                  GUri     *site_for_cookies)
 {
        SoupMessagePrivate *priv;
+        GUri *normalized_site = NULL;
 
        g_return_if_fail (SOUP_IS_MESSAGE (msg));
 
@@ -1966,14 +1971,19 @@ soup_message_set_site_for_cookies (SoupMessage *msg,
        if (priv->site_for_cookies == site_for_cookies)
                return;
 
+        if (site_for_cookies)
+                normalized_site = soup_normalize_uri (site_for_cookies);
+
        if (priv->site_for_cookies) {
-               if (site_for_cookies && soup_uri_equal (priv->site_for_cookies, site_for_cookies))
+               if (normalized_site && soup_uri_equal (priv->site_for_cookies, normalized_site)) {
+                        g_uri_unref (normalized_site);
                        return;
+                }
 
-               soup_uri_free (priv->site_for_cookies);
+               g_uri_unref (priv->site_for_cookies);
        }
 
-       priv->site_for_cookies = site_for_cookies ? soup_uri_copy (site_for_cookies) : NULL;
+       priv->site_for_cookies = normalized_site;
        g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_SITE_FOR_COOKIES);
 }
 
@@ -2107,18 +2117,18 @@ void
 soup_message_set_redirect (SoupMessage *msg, guint status_code,
                           const char *redirect_uri)
 {
-       SoupURI *location;
+       GUri *location;
        char *location_str;
 
-       location = soup_uri_new_with_base (soup_message_get_uri (msg), redirect_uri);
+       location = soup_uri_parse_normalized (soup_message_get_uri (msg), redirect_uri, NULL);
        g_return_if_fail (location != NULL);
 
        soup_message_set_status (msg, status_code);
-       location_str = soup_uri_to_string (location, FALSE);
+       location_str = g_uri_to_string (location);
        soup_message_headers_replace (msg->response_headers, "Location",
                                      location_str);
        g_free (location_str);
-       soup_uri_free (location);
+       g_uri_unref (location);
 }
 
 void
diff --git a/libsoup/soup-message.h b/libsoup/soup-message.h
index 35560bf9..463e8233 100644
--- a/libsoup/soup-message.h
+++ b/libsoup/soup-message.h
@@ -87,7 +87,7 @@ SoupMessage   *soup_message_new                 (const char        *method,
                                                 const char        *uri_string);
 SOUP_AVAILABLE_IN_2_4
 SoupMessage   *soup_message_new_from_uri        (const char        *method,
-                                                SoupURI           *uri);
+                                                GUri              *uri);
 
 SOUP_AVAILABLE_IN_2_4
 void           soup_message_set_response        (SoupMessage       *msg,
@@ -120,20 +120,20 @@ SOUP_AVAILABLE_IN_2_4
 gboolean         soup_message_is_keepalive        (SoupMessage       *msg);
 
 SOUP_AVAILABLE_IN_2_4
-SoupURI         *soup_message_get_uri             (SoupMessage       *msg);
+GUri           *soup_message_get_uri             (SoupMessage       *msg);
 SOUP_AVAILABLE_IN_2_4
 void             soup_message_set_uri             (SoupMessage       *msg,
-                                                  SoupURI           *uri);
+                                                  GUri              *uri);
 SOUP_AVAILABLE_IN_2_30
-SoupURI         *soup_message_get_first_party     (SoupMessage       *msg);
+GUri            *soup_message_get_first_party     (SoupMessage       *msg);
 SOUP_AVAILABLE_IN_2_30
 void             soup_message_set_first_party     (SoupMessage       *msg,
-                                                  SoupURI           *first_party);
+                                                  GUri              *first_party);
 SOUP_AVAILABLE_IN_2_70
-SoupURI         *soup_message_get_site_for_cookies (SoupMessage      *msg);
+GUri            *soup_message_get_site_for_cookies (SoupMessage      *msg);
 SOUP_AVAILABLE_IN_2_70
 void             soup_message_set_site_for_cookies (SoupMessage      *msg,
-                                                   SoupURI          *site_for_cookies);
+                                                   GUri             *site_for_cookies);
 SOUP_AVAILABLE_IN_2_70
 void             soup_message_set_is_top_level_navigation (SoupMessage      *msg,
                                                           gboolean          is_top_level_navigation);
diff --git a/libsoup/soup-misc.h b/libsoup/soup-misc.h
index 770ecf54..8534d037 100644
--- a/libsoup/soup-misc.h
+++ b/libsoup/soup-misc.h
@@ -53,8 +53,6 @@ extern const char soup_char_attributes[];
 char *soup_uri_decoded_copy (const char *str, int length, int *decoded_length);
 char *soup_uri_to_string_internal (SoupURI *uri, gboolean just_path_and_query,
                                   gboolean include_password, gboolean force_port);
-gboolean soup_uri_is_http (SoupURI *uri, char **aliases);
-gboolean soup_uri_is_https (SoupURI *uri, char **aliases);
 
 /* At some point it might be possible to mark additional methods
  * safe or idempotent...
diff --git a/libsoup/soup-request-data.c b/libsoup/soup-request-data.c
index 897ad2a6..75252c30 100644
--- a/libsoup/soup-request-data.c
+++ b/libsoup/soup-request-data.c
@@ -67,10 +67,10 @@ soup_request_data_finalize (GObject *object)
 
 static gboolean
 soup_request_data_check_uri (SoupRequest  *request,
-                            SoupURI      *uri,
+                            GUri         *uri,
                             GError      **error)
 {
-       return uri->host == NULL;
+       return g_uri_get_host (uri) == NULL;
 }
 
 #define BASE64_INDICATOR     ";base64"
@@ -83,13 +83,13 @@ soup_request_data_send (SoupRequest   *request,
 {
        SoupRequestData *data = SOUP_REQUEST_DATA (request);
         SoupRequestDataPrivate *priv = soup_request_data_get_instance_private (data);
-       SoupURI *uri = soup_request_get_uri (request);
+       GUri *uri = soup_request_get_uri (request);
        GInputStream *memstream;
        const char *comma, *start, *end;
        gboolean base64 = FALSE;
        char *uristr;
 
-       uristr = soup_uri_to_string (uri, FALSE);
+       uristr = g_uri_to_string (uri);
        start = uristr + 5;
        comma = strchr (start, ',');
        if (comma && comma != start) {
@@ -101,7 +101,7 @@ soup_request_data_send (SoupRequest   *request,
                        end = comma;
 
                if (end != start)
-                       priv->content_type = soup_uri_decoded_copy (start, end - start, NULL);
+                       priv->content_type = g_uri_unescape_segment (start, end, NULL);
        }
 
        memstream = g_memory_input_stream_new ();
@@ -110,17 +110,18 @@ soup_request_data_send (SoupRequest   *request,
                start = comma + 1;
 
        if (*start) {
-               int decoded_length = 0;
-               guchar *buf = (guchar *) soup_uri_decoded_copy (start, strlen (start),
-                                                               &decoded_length);
+               GBytes *buf = g_uri_unescape_bytes (start, -1, NULL, NULL);
+                gsize data_len;
+                guchar *data = g_bytes_unref_to_data (buf, &data_len);
 
                if (base64)
-                       buf = g_base64_decode_inplace ((gchar*) buf, &priv->content_length);
+                       g_base64_decode_inplace ((char*)data, &priv->content_length);
                else
-                       priv->content_length = decoded_length;
+                       priv->content_length = data_len;
 
                g_memory_input_stream_add_data (G_MEMORY_INPUT_STREAM (memstream),
-                                               buf, priv->content_length,
+                                               data,
+                                                priv->content_length,
                                                g_free);
        }
        g_free (uristr);
diff --git a/libsoup/soup-request-file.c b/libsoup/soup-request-file.c
index 740b52a9..cc5afa31 100644
--- a/libsoup/soup-request-file.c
+++ b/libsoup/soup-request-file.c
@@ -74,16 +74,17 @@ soup_request_file_finalize (GObject *object)
 
 static gboolean
 soup_request_file_check_uri (SoupRequest  *request,
-                            SoupURI      *uri,
+                            GUri         *uri,
                             GError      **error)
 {
+        const char *host = g_uri_get_host (uri);
        /* "file:/foo" is not valid */
-       if (!uri->host)
+       if (!host)
                return FALSE;
 
        /* but it must be "file:///..." or "file://localhost/..." */
-       if (*uri->host &&
-           g_ascii_strcasecmp (uri->host, "localhost") != 0)
+       if (*host &&
+           g_ascii_strcasecmp (host, "localhost") != 0)
                return FALSE;
        return TRUE;
 }
@@ -127,20 +128,20 @@ soup_request_file_ensure_file (SoupRequestFile  *file,
                               GError          **error)
 {
         SoupRequestFilePrivate *priv = soup_request_file_get_instance_private (file);
-       SoupURI *uri;
+       GUri *uri;
        char *decoded_path;
 
        if (priv->gfile)
                return TRUE;
 
        uri = soup_request_get_uri (SOUP_REQUEST (file));
-       decoded_path = soup_uri_decode (uri->path);
+       decoded_path = g_uri_unescape_string (g_uri_get_path (uri), NULL);
 
 #ifdef G_OS_WIN32
        windowsify_file_uri_path (decoded_path);
 #endif
 
-       if (uri->scheme == SOUP_URI_SCHEME_RESOURCE) {
+       if (!g_ascii_strcasecmp (g_uri_get_scheme (uri), "resource")) {
                char *uri_str;
 
                uri_str = g_strdup_printf ("resource://%s", decoded_path);
diff --git a/libsoup/soup-request-http.c b/libsoup/soup-request-http.c
index d4a4cd87..fdc91ec7 100644
--- a/libsoup/soup-request-http.c
+++ b/libsoup/soup-request-http.c
@@ -67,13 +67,13 @@ soup_request_http_init (SoupRequestHTTP *http)
 
 static gboolean
 soup_request_http_check_uri (SoupRequest  *request,
-                            SoupURI      *uri,
+                            GUri      *uri,
                             GError      **error)
 {
        SoupRequestHTTP *http = SOUP_REQUEST_HTTP (request);
         SoupRequestHTTPPrivate *priv = soup_request_http_get_instance_private (http);
 
-       if (!SOUP_URI_VALID_FOR_HTTP (uri))
+       if (!soup_uri_valid_for_http (uri, error))
                return FALSE;
 
        priv->msg = soup_message_new_from_uri (SOUP_METHOD_GET, uri);
diff --git a/libsoup/soup-request.c b/libsoup/soup-request.c
index 6a1f53ba..0275ee4f 100644
--- a/libsoup/soup-request.c
+++ b/libsoup/soup-request.c
@@ -53,7 +53,7 @@ enum {
 };
 
 typedef struct {
-       SoupURI *uri;
+       GUri *uri;
        SoupSession *session;
 } SoupRequestPrivate;
 
@@ -75,7 +75,7 @@ soup_request_finalize (GObject *object)
        SoupRequest *request = SOUP_REQUEST (object);
         SoupRequestPrivate *priv = soup_request_get_instance_private (request);
 
-       g_clear_pointer (&priv->uri, soup_uri_free);
+       g_clear_pointer (&priv->uri, g_uri_unref);
        g_clear_object (&priv->session);
 
        G_OBJECT_CLASS (soup_request_parent_class)->finalize (object);
@@ -93,8 +93,8 @@ soup_request_set_property (GObject      *object,
        switch (prop_id) {
        case PROP_URI:
                if (priv->uri)
-                       soup_uri_free (priv->uri);
-               priv->uri = g_value_dup_boxed (value);
+                       g_uri_unref (priv->uri);
+               priv->uri = soup_normalize_uri (g_value_get_boxed (value));
                break;
        case PROP_SESSION:
                if (priv->session)
@@ -148,10 +148,10 @@ soup_request_initable_init (GInitable     *initable,
                check_uri (request, priv->uri, error);
 
        if (!ok && error && !*error) {
-               char *uri_string = soup_uri_to_string (priv->uri, FALSE);
+               char *uri_string = g_uri_to_string_partial (priv->uri, G_URI_HIDE_PASSWORD);
                g_set_error (error, SOUP_REQUEST_ERROR, SOUP_REQUEST_ERROR_BAD_URI,
                             _("Invalid “%s” URI: %s"),
-                            priv->uri->scheme,
+                            g_uri_get_scheme (priv->uri),
                             uri_string);
                g_free (uri_string);
        }
@@ -161,7 +161,7 @@ soup_request_initable_init (GInitable     *initable,
 
 static gboolean
 soup_request_default_check_uri (SoupRequest  *request,
-                               SoupURI      *uri,
+                               GUri         *uri,
                                GError      **error)
 {
        return TRUE;
@@ -295,7 +295,7 @@ soup_request_class_init (SoupRequestClass *request_class)
                 g_param_spec_boxed (SOUP_REQUEST_URI,
                                     "URI",
                                     "The request URI",
-                                    SOUP_TYPE_URI,
+                                    G_TYPE_URI,
                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                                     G_PARAM_STATIC_STRINGS));
        /**
@@ -338,7 +338,7 @@ soup_request_initable_interface_init (GInitableIface *initable_interface)
  *
  * Since: 2.42
  */
-SoupURI *
+GUri *
 soup_request_get_uri (SoupRequest *request)
 {
         SoupRequestPrivate *priv = soup_request_get_instance_private (request);
diff --git a/libsoup/soup-request.h b/libsoup/soup-request.h
index fbb6b22a..3994809d 100644
--- a/libsoup/soup-request.h
+++ b/libsoup/soup-request.h
@@ -37,7 +37,7 @@ struct _SoupRequestClass {
        const char **schemes;
 
        gboolean       (*check_uri)          (SoupRequest          *req_base,
-                                             SoupURI              *uri,
+                                             GUri                 *uri,
                                              GError              **error);
 
        GInputStream * (*send)               (SoupRequest          *request,
@@ -73,7 +73,7 @@ GInputStream *soup_request_send_finish        (SoupRequest          *request,
                                               GError              **error);
 
 SOUP_AVAILABLE_IN_2_34
-SoupURI      *soup_request_get_uri            (SoupRequest          *request);
+GUri         *soup_request_get_uri            (SoupRequest          *request);
 SOUP_AVAILABLE_IN_2_34
 SoupSession  *soup_request_get_session        (SoupRequest          *request);
 
diff --git a/libsoup/soup-server.c b/libsoup/soup-server.c
index aa5f2203..a3ce755b 100644
--- a/libsoup/soup-server.c
+++ b/libsoup/soup-server.c
@@ -919,10 +919,10 @@ static SoupServerHandler *
 get_handler (SoupServer *server, SoupMessage *msg)
 {
        SoupServerPrivate *priv = soup_server_get_instance_private (server);
-       SoupURI *uri;
+       GUri *uri;
 
        uri = soup_message_get_uri (msg);
-       return soup_path_map_lookup (priv->handlers, NORMALIZED_PATH (uri->path));
+       return soup_path_map_lookup (priv->handlers, NORMALIZED_PATH (g_uri_get_path (uri)));
 }
 
 static void
@@ -931,7 +931,7 @@ call_handler (SoupServer *server, SoupServerHandler *handler,
              gboolean early)
 {
        GHashTable *form_data_set;
-       SoupURI *uri;
+       GUri *uri;
 
        if (early && !handler->early_callback)
                return;
@@ -942,18 +942,18 @@ call_handler (SoupServer *server, SoupServerHandler *handler,
                return;
 
        uri = soup_message_get_uri (msg);
-       if (uri->query)
-               form_data_set = soup_form_decode (uri->query);
+       if (g_uri_get_query (uri))
+               form_data_set = soup_form_decode (g_uri_get_query (uri));
        else
                form_data_set = NULL;
 
        if (early) {
                (*handler->early_callback) (server, msg,
-                                           uri->path, form_data_set,
+                                           g_uri_get_path (uri), form_data_set,
                                            client, handler->early_user_data);
        } else {
                (*handler->callback) (server, msg,
-                                     uri->path, form_data_set,
+                                     g_uri_get_path (uri), form_data_set,
                                      client, handler->user_data);
        }
 
@@ -961,13 +961,30 @@ call_handler (SoupServer *server, SoupServerHandler *handler,
                g_hash_table_unref (form_data_set);
 }
 
+static GUri *
+uri_set_path (GUri *uri, const char *path)
+{
+        return g_uri_build_with_user (
+                g_uri_get_flags (uri) ^ G_URI_FLAGS_ENCODED_PATH,
+                g_uri_get_scheme (uri),
+                g_uri_get_user (uri),
+                g_uri_get_password (uri),
+                g_uri_get_auth_params (uri),
+                g_uri_get_host (uri),
+                g_uri_get_port (uri),
+                path,
+                g_uri_get_query (uri),
+                g_uri_get_fragment (uri)
+        );
+}
+
 static void
 got_headers (SoupMessage *msg, SoupClientContext *client)
 {
        SoupServer *server = client->server;
        SoupServerPrivate *priv = soup_server_get_instance_private (server);
        SoupServerHandler *handler;
-       SoupURI *uri;
+       GUri *uri;
        GDateTime *date;
        char *date_string;
        SoupAuthDomain *domain;
@@ -993,10 +1010,10 @@ got_headers (SoupMessage *msg, SoupClientContext *client)
                return;
        }
 
-       if (!priv->raw_paths) {
+       if (!priv->raw_paths && g_uri_get_flags (uri) & G_URI_FLAGS_ENCODED_PATH) {
                char *decoded_path;
 
-               decoded_path = soup_uri_decode (uri->path);
+                decoded_path = g_uri_unescape_string (g_uri_get_path (uri), NULL);
 
                if (strstr (decoded_path, "/../") ||
                    g_str_has_suffix (decoded_path, "/..")
@@ -1014,7 +1031,8 @@ got_headers (SoupMessage *msg, SoupClientContext *client)
                        return;
                }
 
-               soup_uri_set_path (uri, decoded_path);
+                uri = uri_set_path (uri, decoded_path);
+                soup_message_set_uri (msg, uri);
                g_free (decoded_path);
        }
 
@@ -1060,7 +1078,7 @@ complete_websocket_upgrade (SoupMessage *msg, gpointer user_data)
 {
        SoupClientContext *client = user_data;
        SoupServer *server = client->server;
-       SoupURI *uri = soup_message_get_uri (msg);
+       GUri *uri = soup_message_get_uri (msg);
        SoupServerHandler *handler;
        GIOStream *stream;
        SoupWebsocketConnection *conn;
@@ -1080,7 +1098,7 @@ complete_websocket_upgrade (SoupMessage *msg, gpointer user_data)
        g_object_unref (stream);
        soup_client_context_unref (client);
 
-       (*handler->websocket_callback) (server, conn, uri->path, client,
+       (*handler->websocket_callback) (server, conn, g_uri_get_path (uri), client,
                                        handler->websocket_user_data);
        g_object_unref (conn);
        soup_client_context_unref (client);
@@ -1637,8 +1655,8 @@ soup_server_listen_socket (SoupServer *server, GSocket *socket,
  * <literal>::</literal>, rather than actually returning separate URIs
  * for each interface on the system.
  *
- * Return value: (transfer full) (element-type Soup.URI): a list of
- * #SoupURIs, which you must free when you are done with it.
+ * Return value: (transfer full) (element-type GUri): a list of
+ * #GUris, which you must free when you are done with it.
  *
  * Since: 2.48
  */
@@ -1651,7 +1669,8 @@ soup_server_get_uris (SoupServer *server)
        GInetSocketAddress *addr;
        GInetAddress *inet_addr;
        char *ip;
-       SoupURI *uri;
+        int port;
+       GUri *uri;
        gpointer creds;
 
        g_return_val_if_fail (SOUP_IS_SERVER (server), NULL);
@@ -1662,13 +1681,15 @@ soup_server_get_uris (SoupServer *server)
                addr = soup_socket_get_local_address (listener);
                inet_addr = g_inet_socket_address_get_address (addr);
                ip = g_inet_address_to_string (inet_addr);
+                port = g_inet_socket_address_get_port (addr);
                g_object_get (G_OBJECT (listener), SOUP_SOCKET_SSL_CREDENTIALS, &creds, NULL);
 
-               uri = soup_uri_new (NULL);
-               soup_uri_set_scheme (uri, creds ? "https" : "http");
-               soup_uri_set_host (uri, ip);
-               soup_uri_set_port (uri, g_inet_socket_address_get_port (addr));
-               soup_uri_set_path (uri, "/");
+                if (port == 0)
+                        port = -1;
+
+                uri = g_uri_build (SOUP_HTTP_URI_FLAGS,
+                                   creds ? "https" : "http",
+                                   NULL, ip, port, "/", NULL, NULL);
 
                uris = g_slist_prepend (uris, uri);
 
diff --git a/libsoup/soup-session-private.h b/libsoup/soup-session-private.h
index 57ce3fd1..a12dfedd 100644
--- a/libsoup/soup-session-private.h
+++ b/libsoup/soup-session-private.h
@@ -7,11 +7,10 @@
 #define __SOUP_SESSION_PRIVATE_H__ 1
 
 #include "soup-session.h"
-#include "soup-uri.h"
 
 G_BEGIN_DECLS
 
-SoupURI *soup_session_get_message_proxy_uri (SoupSession *session,
+GUri    *soup_session_get_message_proxy_uri (SoupSession *session,
                                             SoupMessage *msg);
 void     soup_session_requeue_message       (SoupSession *session,
                                             SoupMessage *msg);
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index ce7dc713..46764a6b 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -68,7 +68,7 @@
  **/
 
 typedef struct {
-       SoupURI         *uri;
+       GUri            *uri;
        GNetworkAddress *addr;
 
        GSList      *connections;      /* CONTAINS: SoupConnection */
@@ -100,7 +100,7 @@ typedef struct {
        GResolver *resolver;
        GProxyResolver *proxy_resolver;
        gboolean proxy_use_default;
-       SoupURI *proxy_uri;
+       GUri *proxy_uri;
 
        SoupSocketProperties *socket_props;
 
@@ -310,7 +310,7 @@ soup_session_finalize (GObject *object)
 
        g_object_unref (priv->resolver);
        g_clear_object (&priv->proxy_resolver);
-       g_clear_pointer (&priv->proxy_uri, soup_uri_free);
+       g_clear_pointer (&priv->proxy_uri, g_uri_unref);
 
        g_free (priv->http_aliases);
        g_free (priv->https_aliases);
@@ -425,19 +425,19 @@ set_aliases (char ***variable, char **value)
 }
 
 static void
-set_proxy_resolver (SoupSession *session, SoupURI *uri,
+set_proxy_resolver (SoupSession *session, GUri *uri,
                    GProxyResolver *g_resolver)
 {
        SoupSessionPrivate *priv = soup_session_get_instance_private (session);
        g_clear_object (&priv->proxy_resolver);
-       g_clear_pointer (&priv->proxy_uri, soup_uri_free);
+       g_clear_pointer (&priv->proxy_uri, g_uri_unref);
        priv->proxy_use_default = FALSE;
 
        if (uri) {
                char *uri_string;
 
-               priv->proxy_uri = soup_uri_copy (uri);
-               uri_string = soup_uri_to_string_internal (uri, FALSE, TRUE, TRUE);
+               priv->proxy_uri = g_uri_ref (uri);
+               uri_string = g_uri_to_string (uri);
                priv->proxy_resolver = g_simple_proxy_resolver_new (uri_string, NULL);
                g_free (uri_string);
        } else if (g_resolver)
@@ -675,50 +675,71 @@ soup_session_new_with_options (const char *optname1,
 static guint
 soup_host_uri_hash (gconstpointer key)
 {
-       const SoupURI *uri = key;
+       GUri *uri = (GUri*)key;
 
-       g_return_val_if_fail (uri != NULL && uri->host != NULL, 0);
+       g_return_val_if_fail (uri != NULL && g_uri_get_host (uri) != NULL, 0);
 
-       return uri->port + soup_str_case_hash (uri->host);
+       return g_uri_get_port (uri) + soup_str_case_hash (g_uri_get_host (uri));
 }
 
 static gboolean
 soup_host_uri_equal (gconstpointer v1, gconstpointer v2)
 {
-       const SoupURI *one = v1;
-       const SoupURI *two = v2;
+       GUri *one = (GUri*)v1;
+       GUri *two = (GUri*)v2;
 
        g_return_val_if_fail (one != NULL && two != NULL, one == two);
-       g_return_val_if_fail (one->host != NULL && two->host != NULL, one->host == two->host);
 
-       if (one->port != two->port)
+        const char *one_host = g_uri_get_host (one);
+        const char *two_host = g_uri_get_host (two);
+       g_return_val_if_fail (one_host != NULL && two_host != NULL, one_host == two_host);
+
+       if (g_uri_get_port (one) != g_uri_get_port (two))
                return FALSE;
 
-       return g_ascii_strcasecmp (one->host, two->host) == 0;
+       return g_ascii_strcasecmp (one_host, two_host) == 0;
+}
+
+static GUri *
+copy_uri_with_new_scheme (GUri *uri, const char *scheme)
+{
+        return g_uri_build_with_user (
+                g_uri_get_flags (uri),
+                scheme,
+                g_uri_get_user (uri),
+                g_uri_get_password (uri),
+                g_uri_get_auth_params (uri),
+                g_uri_get_host (uri),
+                g_uri_get_port (uri),
+                g_uri_get_path (uri),
+                g_uri_get_query (uri),
+                g_uri_get_fragment (uri)
+        );
 }
 
 
 static SoupSessionHost *
-soup_session_host_new (SoupSession *session, SoupURI *uri)
+soup_session_host_new (SoupSession *session, GUri *uri)
 {
        SoupSessionHost *host;
+        const char *scheme = g_uri_get_scheme (uri);
 
        host = g_slice_new0 (SoupSessionHost);
-       host->uri = soup_uri_copy_host (uri);
-       if (host->uri->scheme != SOUP_URI_SCHEME_HTTP &&
-           host->uri->scheme != SOUP_URI_SCHEME_HTTPS) {
+       if (g_ascii_strcasecmp (scheme, "http") &&
+           g_ascii_strcasecmp (scheme, "https")) {
                SoupSessionPrivate *priv = soup_session_get_instance_private (session);
 
-               if (soup_uri_is_https (host->uri, priv->https_aliases))
-                       host->uri->scheme = SOUP_URI_SCHEME_HTTPS;
+               if (soup_uri_is_https (uri, priv->https_aliases))
+                        host->uri = copy_uri_with_new_scheme (uri, "https");
                else
-                       host->uri->scheme = SOUP_URI_SCHEME_HTTP;
-       }
+                       host->uri = copy_uri_with_new_scheme (uri, "http");
+       } else
+                host->uri = g_uri_ref (uri);
 
        host->addr = g_object_new (G_TYPE_NETWORK_ADDRESS,
-                                  "hostname", host->uri->host,
-                                  "port", host->uri->port,
-                                  "scheme", host->uri->scheme,
+                                  "hostname", g_uri_get_host (host->uri),
+                                  "port", soup_uri_get_port_with_default (host->uri),
+                                  "scheme", g_uri_get_scheme (host->uri),
                                   NULL);
        host->keep_alive_src = NULL;
        host->session = session;
@@ -728,12 +749,12 @@ soup_session_host_new (SoupSession *session, SoupURI *uri)
 
 /* Requires conn_lock to be locked */
 static SoupSessionHost *
-get_host_for_uri (SoupSession *session, SoupURI *uri)
+get_host_for_uri (SoupSession *session, GUri *uri)
 {
        SoupSessionPrivate *priv = soup_session_get_instance_private (session);
        SoupSessionHost *host;
        gboolean https;
-       SoupURI *uri_tmp = NULL;
+       GUri *uri_tmp = NULL;
 
        https = soup_uri_is_https (uri, priv->https_aliases);
        if (https)
@@ -743,14 +764,12 @@ get_host_for_uri (SoupSession *session, SoupURI *uri)
        if (host)
                return host;
 
-       if (uri->scheme != SOUP_URI_SCHEME_HTTP &&
-           uri->scheme != SOUP_URI_SCHEME_HTTPS) {
-               uri = uri_tmp = soup_uri_copy (uri);
-               uri->scheme = https ? SOUP_URI_SCHEME_HTTPS : SOUP_URI_SCHEME_HTTP;
+       if (!soup_uri_is_http (uri, NULL) && !soup_uri_is_https (uri, NULL)) {
+               uri = uri_tmp = copy_uri_with_new_scheme (uri, https ? "https" : "http");
        }
        host = soup_session_host_new (session, uri);
        if (uri_tmp)
-               soup_uri_free (uri_tmp);
+               g_uri_unref (uri_tmp);
 
        if (https)
                g_hash_table_insert (priv->https_hosts, host->uri, host);
@@ -777,7 +796,7 @@ free_host (SoupSessionHost *host)
                g_source_unref (host->keep_alive_src);
        }
 
-       soup_uri_free (host->uri);
+       g_uri_unref (host->uri);
        g_object_unref (host->addr);
        g_slice_free (SoupSessionHost, host);
 }
@@ -804,20 +823,23 @@ auth_manager_authenticate (SoupAuthManager *manager, SoupMessage *msg,
          (msg)->status_code == SOUP_STATUS_FOUND) && \
         SOUP_METHOD_IS_SAFE ((msg)->method))
 
-static inline SoupURI *
+static inline GUri *
 redirection_uri (SoupMessage *msg)
 {
        const char *new_loc;
-       SoupURI *new_uri;
+       GUri *new_uri;
 
        new_loc = soup_message_headers_get_one (msg->response_headers,
                                                "Location");
        if (!new_loc)
                return NULL;
-       new_uri = soup_uri_new_with_base (soup_message_get_uri (msg), new_loc);
-       if (!new_uri || !new_uri->host) {
-               if (new_uri)
-                       soup_uri_free (new_uri);
+
+        new_uri = soup_uri_parse_normalized (soup_message_get_uri (msg), new_loc, NULL);
+       if (!new_uri)
+                return NULL;
+        
+        if (!g_uri_get_host (new_uri)) {
+               g_uri_unref (new_uri);
                return NULL;
        }
 
@@ -841,7 +863,7 @@ gboolean
 soup_session_would_redirect (SoupSession *session, SoupMessage *msg)
 {
        SoupSessionPrivate *priv = soup_session_get_instance_private (session);
-       SoupURI *new_uri;
+       GUri *new_uri;
 
        /* It must have an appropriate status code and method */
        if (!SOUP_SESSION_WOULD_REDIRECT_AS_GET (session, msg) &&
@@ -854,14 +876,14 @@ soup_session_would_redirect (SoupSession *session, SoupMessage *msg)
        new_uri = redirection_uri (msg);
        if (!new_uri)
                return FALSE;
-       if (!new_uri->host || !*new_uri->host ||
+       if (!g_uri_get_host (new_uri) || !*g_uri_get_host (new_uri) ||
            (!soup_uri_is_http (new_uri, priv->http_aliases) &&
             !soup_uri_is_https (new_uri, priv->https_aliases))) {
-               soup_uri_free (new_uri);
+               g_uri_unref (new_uri);
                return FALSE;
        }
 
-       soup_uri_free (new_uri);
+       g_uri_unref (new_uri);
        return TRUE;
 }
 
@@ -892,7 +914,7 @@ soup_session_would_redirect (SoupSession *session, SoupMessage *msg)
 gboolean
 soup_session_redirect_message (SoupSession *session, SoupMessage *msg)
 {
-       SoupURI *new_uri;
+       GUri *new_uri;
 
        new_uri = redirection_uri (msg);
        if (!new_uri)
@@ -910,7 +932,7 @@ soup_session_redirect_message (SoupSession *session, SoupMessage *msg)
        }
 
        soup_message_set_uri (msg, new_uri);
-       soup_uri_free (new_uri);
+       g_uri_unref (new_uri);
 
        soup_session_requeue_message (session, msg);
        return TRUE;
@@ -1092,6 +1114,7 @@ free_unused_host (gpointer user_data)
 {
        SoupSessionHost *host = (SoupSessionHost *) user_data;
        SoupSessionPrivate *priv = soup_session_get_instance_private (host->session);
+       GUri *uri = host->uri;
 
        g_mutex_lock (&priv->conn_lock);
 
@@ -1106,10 +1129,10 @@ free_unused_host (gpointer user_data)
        /* This will free the host in addition to removing it from the
         * hash table
         */
-       if (host->uri->scheme == SOUP_URI_SCHEME_HTTPS)
-               g_hash_table_remove (priv->https_hosts, host->uri);
+       if (soup_uri_is_https (uri, NULL))
+               g_hash_table_remove (priv->https_hosts, uri);
        else
-               g_hash_table_remove (priv->http_hosts, host->uri);
+               g_hash_table_remove (priv->http_hosts, uri);
        g_mutex_unlock (&priv->conn_lock);
 
        return FALSE;
@@ -1236,7 +1259,7 @@ soup_session_set_item_status (SoupSession          *session,
                              guint                 status_code,
                              GError               *error)
 {
-       SoupURI *uri = NULL;
+       GUri *uri = NULL;
 
        switch (status_code) {
        case SOUP_STATUS_CANT_RESOLVE:
@@ -1264,10 +1287,10 @@ soup_session_set_item_status (SoupSession          *session,
 
        if (error)
                soup_message_set_status_full (item->msg, status_code, error->message);
-       else if (uri && uri->host) {
+       else if (uri && g_uri_get_host (uri)) {
                char *msg = g_strdup_printf ("%s (%s)",
                                             soup_status_get_phrase (status_code),
-                                            uri->host);
+                                            g_uri_get_host (uri));
                soup_message_set_status_full (item->msg, status_code, msg);
                g_free (msg);
        } else
@@ -1423,7 +1446,7 @@ tunnel_connect (SoupMessageQueueItem *item)
 {
        SoupSession *session = item->session;
        SoupMessageQueueItem *tunnel_item;
-       SoupURI *uri;
+       GUri *uri;
        SoupMessage *msg;
 
        item->state = SOUP_MESSAGE_TUNNELING;
@@ -3757,26 +3780,28 @@ SoupRequest *
 soup_session_request (SoupSession *session, const char *uri_string,
                      GError **error)
 {
-       SoupURI *uri;
+       GUri *uri;
        SoupRequest *req;
+        GError *local_error = NULL;
 
-       uri = soup_uri_new (uri_string);
+       uri = g_uri_parse (uri_string, SOUP_HTTP_URI_FLAGS, &local_error);
        if (!uri) {
                g_set_error (error, SOUP_REQUEST_ERROR,
                             SOUP_REQUEST_ERROR_BAD_URI,
-                            _("Could not parse URI “%s”"), uri_string);
+                            _("Could not parse URI “%s”: %s"), uri_string, local_error->message);
+                g_error_free (local_error);
                return NULL;
        }
 
        req = soup_session_request_uri (session, uri, error);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        return req;
 }
 
 /**
  * soup_session_request_uri:
  * @session: a #SoupSession
- * @uri: a #SoupURI representing the URI to retrieve
+ * @uri: a #GUri representing the URI to retrieve
  * @error: return location for a #GError, or %NULL
  *
  * Creates a #SoupRequest for retrieving @uri.
@@ -3787,7 +3812,7 @@ soup_session_request (SoupSession *session, const char *uri_string,
  * Since: 2.42
  */
 SoupRequest *
-soup_session_request_uri (SoupSession *session, SoupURI *uri,
+soup_session_request_uri (SoupSession *session, GUri *uri,
                          GError **error)
 {
        SoupSessionPrivate *priv;
@@ -3797,11 +3822,11 @@ soup_session_request_uri (SoupSession *session, SoupURI *uri,
 
        priv = soup_session_get_instance_private (session);
 
-       request_type = (GType)GPOINTER_TO_SIZE (g_hash_table_lookup (priv->request_types, uri->scheme));
+       request_type = (GType)GPOINTER_TO_SIZE (g_hash_table_lookup (priv->request_types, g_uri_get_scheme 
(uri)));
        if (!request_type) {
                g_set_error (error, SOUP_REQUEST_ERROR,
                             SOUP_REQUEST_ERROR_UNSUPPORTED_URI_SCHEME,
-                            _("Unsupported URI scheme “%s”"), uri->scheme);
+                            _("Unsupported URI scheme “%s”"), g_uri_get_scheme (uri));
                return NULL;
        }
 
@@ -3872,7 +3897,7 @@ soup_session_request_http (SoupSession  *session,
  * soup_session_request_http_uri:
  * @session: a #SoupSession
  * @method: an HTTP method
- * @uri: a #SoupURI representing the URI to retrieve
+ * @uri: a #GUri representing the URI to retrieve
  * @error: return location for a #GError, or %NULL
  *
  * Creates a #SoupRequest for retrieving @uri, which must be an
@@ -3887,7 +3912,7 @@ soup_session_request_http (SoupSession  *session,
 SoupRequestHTTP *
 soup_session_request_http_uri (SoupSession  *session,
                               const char   *method,
-                              SoupURI      *uri,
+                              GUri         *uri,
                               GError      **error)
 {
        SoupRequest *req;
@@ -4175,13 +4200,13 @@ soup_session_websocket_connect_finish (SoupSession      *session,
        return g_task_propagate_pointer (G_TASK (result), error);
 }
 
-SoupURI *
+GUri *
 soup_session_get_message_proxy_uri (SoupSession *session,
                                    SoupMessage *msg)
 {
        SoupSessionPrivate *priv = soup_session_get_instance_private (session);
        SoupMessageQueueItem *item;
-       SoupURI *uri;
+       GUri *uri;
 
        item = soup_message_queue_lookup (priv->queue, msg);
        if (!item)
diff --git a/libsoup/soup-session.h b/libsoup/soup-session.h
index a4bcfac7..8ea2e8f1 100644
--- a/libsoup/soup-session.h
+++ b/libsoup/soup-session.h
@@ -115,7 +115,7 @@ SoupRequest     *soup_session_request          (SoupSession  *session,
                                                GError      **error);
 SOUP_AVAILABLE_IN_2_42
 SoupRequest     *soup_session_request_uri      (SoupSession  *session,
-                                               SoupURI      *uri,
+                                               GUri         *uri,
                                                GError      **error);
 SOUP_AVAILABLE_IN_2_42
 SoupRequestHTTP *soup_session_request_http     (SoupSession  *session,
@@ -125,7 +125,7 @@ SoupRequestHTTP *soup_session_request_http     (SoupSession  *session,
 SOUP_AVAILABLE_IN_2_42
 SoupRequestHTTP *soup_session_request_http_uri (SoupSession  *session,
                                                const char   *method,
-                                               SoupURI      *uri,
+                                               GUri         *uri,
                                                GError      **error);
 
 SOUP_AVAILABLE_IN_2_42
diff --git a/libsoup/soup-socket-private.h b/libsoup/soup-socket-private.h
index 9384de58..fceeda44 100644
--- a/libsoup/soup-socket-private.h
+++ b/libsoup/soup-socket-private.h
@@ -40,7 +40,7 @@ GSocket   *soup_socket_steal_gsocket           (SoupSocket           *sock);
 GIOStream *soup_socket_get_connection          (SoupSocket           *sock);
 GIOStream *soup_socket_get_iostream            (SoupSocket           *sock);
 
-SoupURI   *soup_socket_get_http_proxy_uri      (SoupSocket           *sock);
+GUri      *soup_socket_get_http_proxy_uri      (SoupSocket           *sock);
 
 gboolean   soup_socket_listen_full             (SoupSocket           *sock,
                                                 GError              **error);
diff --git a/libsoup/soup-socket.c b/libsoup/soup-socket.c
index 5b0c604c..fe19d490 100644
--- a/libsoup/soup-socket.c
+++ b/libsoup/soup-socket.c
@@ -1612,13 +1612,13 @@ soup_socket_get_remote_address (SoupSocket *sock)
         return priv->remote_addr;
 }
 
-SoupURI *
+GUri *
 soup_socket_get_http_proxy_uri (SoupSocket *sock)
 {
        SoupSocketPrivate *priv = soup_socket_get_instance_private (sock);
        GSocketAddress *addr;
        GProxyAddress *paddr;
-       SoupURI *uri;
+       GUri *uri;
 
        if (!priv->gsock)
                return NULL;
@@ -1630,10 +1630,10 @@ soup_socket_get_http_proxy_uri (SoupSocket *sock)
        }
 
        paddr = G_PROXY_ADDRESS (addr);
-       if (strcmp (g_proxy_address_get_protocol (paddr), "http") != 0)
+       if (g_ascii_strcasecmp (g_proxy_address_get_protocol (paddr), "http") != 0)
                return NULL;
 
-       uri = soup_uri_new (g_proxy_address_get_uri (paddr));
+       uri = soup_uri_parse_normalized (NULL, g_proxy_address_get_uri (paddr), NULL);
        g_object_unref (addr);
        return uri;
 }
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index fd8dc828..672a4b8f 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -16,797 +16,160 @@
 #include "soup.h"
 #include "soup-misc.h"
 
-/**
- * SECTION:soup-uri
- * @short_description: URIs
- *
- * A #SoupURI represents a (parsed) URI.
- *
- * Many applications will not need to use #SoupURI directly at all; on
- * the client side, soup_message_new() takes a stringified URI, and on
- * the server side, the path and query components are provided for you
- * in the server callback.
- **/
-
-/**
- * SoupURI:
- * @scheme: the URI scheme (eg, "http")
- * @user: a username, or %NULL
- * @password: a password, or %NULL
- * @host: the hostname or IP address, or %NULL
- * @port: the port number on @host
- * @path: the path on @host
- * @query: a query for @path, or %NULL
- * @fragment: a fragment identifier within @path, or %NULL
- *
- * A #SoupURI represents a (parsed) URI. #SoupURI supports RFC 3986
- * (URI Generic Syntax), and can parse any valid URI. However, libsoup
- * only uses "http" and "https" URIs internally; You can use
- * SOUP_URI_VALID_FOR_HTTP() to test if a #SoupURI is a valid HTTP
- * URI.
- *
- * @scheme will always be set in any URI. It is an interned string and
- * is always all lowercase. (If you parse a URI with a non-lowercase
- * scheme, it will be converted to lowercase.) The macros
- * %SOUP_URI_SCHEME_HTTP and %SOUP_URI_SCHEME_HTTPS provide the
- * interned values for "http" and "https" and can be compared against
- * URI @scheme values.
- *
- * @user and @password are parsed as defined in the older URI specs
- * (ie, separated by a colon; RFC 3986 only talks about a single
- * "userinfo" field). Note that @password is not included in the
- * output of soup_uri_to_string(). libsoup does not normally use these
- * fields; authentication is handled via #SoupSession signals.
- *
- * @host contains the hostname, and @port the port specified in the
- * URI. If the URI doesn't contain a hostname, @host will be %NULL,
- * and if it doesn't specify a port, @port may be 0. However, for
- * "http" and "https" URIs, @host is guaranteed to be non-%NULL
- * (trying to parse an http URI with no @host will return %NULL), and
- * @port will always be non-0 (because libsoup knows the default value
- * to use when it is not specified in the URI).
- *
- * @path is always non-%NULL. For http/https URIs, @path will never be
- * an empty string either; if the input URI has no path, the parsed
- * #SoupURI will have a @path of "/".
- *
- * @query and @fragment are optional for all URI types.
- * soup_form_decode() may be useful for parsing @query.
- *
- * Note that @path, @query, and @fragment may contain
- * %<!-- -->-encoded characters. soup_uri_new() calls
- * soup_uri_normalize() on them, but not soup_uri_decode(). This is
- * necessary to ensure that soup_uri_to_string() will generate a URI
- * that has exactly the same meaning as the original. (In theory,
- * #SoupURI should leave @user, @password, and @host partially-encoded
- * as well, but this would be more annoying than useful.)
- **/
-
-/**
- * SOUP_URI_IS_VALID:
- * @uri: a #SoupURI
- *
- * Tests whether @uri is a valid #SoupURI; that is, that it is non-%NULL
- * and its @scheme and @path members are also non-%NULL.
- *
- * This macro does not check whether http and https URIs have a non-%NULL
- * @host member.
- *
- * Return value: %TRUE if @uri is valid for use.
- *
- * Since: 2.38
- **/
-
-/**
- * SOUP_URI_VALID_FOR_HTTP:
- * @uri: a #SoupURI
- *
- * Tests if @uri is a valid #SoupURI for HTTP communication; that is, if
- * it can be used to construct a #SoupMessage.
- *
- * Return value: %TRUE if @uri is a valid "http" or "https" URI.
- *
- * Since: 2.24
- **/
-
-/**
- * SOUP_URI_SCHEME_HTTP:
- *
- * "http" as an interned string; you can compare this directly to a
- * #SoupURI's <literal>scheme</literal> field using
- * <literal>==</literal>.
- */
-/**
- * SOUP_URI_SCHEME_HTTPS:
- *
- * "https" as an interned string; you can compare this directly to a
- * #SoupURI's <literal>scheme</literal> field using
- * <literal>==</literal>.
- */
-/**
- * SOUP_URI_SCHEME_FTP:
- *
- * "ftp" as an interned string; you can compare this directly to a
- * #SoupURI's <literal>scheme</literal> field using
- * <literal>==</literal>.
- *
- * Since: 2.30
- */
-/**
- * SOUP_URI_SCHEME_FILE:
- *
- * "file" as an interned string; you can compare this directly to a
- * #SoupURI's <literal>scheme</literal> field using
- * <literal>==</literal>.
- *
- * Since: 2.30
- */
-/**
- * SOUP_URI_SCHEME_DATA:
- *
- * "data" as an interned string; you can compare this directly to a
- * #SoupURI's <literal>scheme</literal> field using
- * <literal>==</literal>.
- *
- * Since: 2.30
- */
-/**
- * SOUP_URI_SCHEME_RESOURCE:
- *
- * "data" as an interned string; you can compare this directly to a
- * #SoupURI's <literal>scheme</literal> field using
- * <literal>==</literal>.
- *
- * Since: 2.42
- */
-/**
- * SOUP_URI_SCHEME_WS:
- *
- * "ws" (WebSocket) as an interned string; you can compare this
- * directly to a #SoupURI's <literal>scheme</literal> field using
- * <literal>==</literal>.
- *
- * Since: 2.50
- */
-/**
- * SOUP_URI_SCHEME_WSS:
- *
- * "wss" (WebSocket over TLS) as an interned string; you can compare
- * this directly to a #SoupURI's <literal>scheme</literal> field using
- * <literal>==</literal>.
- *
- * Since: 2.50
- */
-
-static void append_uri_encoded (GString *str, const char *in, const char *extra_enc_chars);
-static char *uri_normalized_copy (const char *str, int length, const char *unescape_extra);
-
-gpointer _SOUP_URI_SCHEME_HTTP, _SOUP_URI_SCHEME_HTTPS;
-gpointer _SOUP_URI_SCHEME_WS, _SOUP_URI_SCHEME_WSS;
-gpointer _SOUP_URI_SCHEME_FTP;
-gpointer _SOUP_URI_SCHEME_FILE, _SOUP_URI_SCHEME_DATA, _SOUP_URI_SCHEME_RESOURCE;
-
-static inline const char *
-soup_uri_parse_scheme (const char *scheme, int len)
-{
-       if (len == 4 && !g_ascii_strncasecmp (scheme, "http", len)) {
-               return SOUP_URI_SCHEME_HTTP;
-       } else if (len == 5 && !g_ascii_strncasecmp (scheme, "https", len)) {
-               return SOUP_URI_SCHEME_HTTPS;
-       } else if (len == 8 && !g_ascii_strncasecmp (scheme, "resource", len)) {
-               return SOUP_URI_SCHEME_RESOURCE;
-       } else if (len == 2 && !g_ascii_strncasecmp (scheme, "ws", len)) {
-               return SOUP_URI_SCHEME_WS;
-       } else if (len == 3 && !g_ascii_strncasecmp (scheme, "wss", len)) {
-               return SOUP_URI_SCHEME_WSS;
-       } else {
-               char *lower_scheme;
-
-               lower_scheme = g_ascii_strdown (scheme, len);
-               scheme = g_intern_static_string (lower_scheme);
-               if (scheme != (const char *)lower_scheme)
-                       g_free (lower_scheme);
-               return scheme;
-       }
-}
-
-static inline guint
+static inline int
 soup_scheme_default_port (const char *scheme)
 {
-       if (scheme == SOUP_URI_SCHEME_HTTP || scheme == SOUP_URI_SCHEME_WS)
+        if (!g_ascii_strcasecmp (scheme, "http") ||
+            !g_ascii_strcasecmp (scheme, "ws"))
                return 80;
-       else if (scheme == SOUP_URI_SCHEME_HTTPS || scheme == SOUP_URI_SCHEME_WSS)
+       else if (!g_ascii_strcasecmp (scheme, "https") ||
+                 !g_ascii_strcasecmp (scheme, "wss"))
                return 443;
-       else if (scheme == SOUP_URI_SCHEME_FTP)
+       else if (!g_ascii_strcasecmp (scheme, "ftp"))
                return 21;
        else
-               return 0;
+               return -1;
 }
 
-/**
- * soup_uri_new_with_base: (constructor)
- * @base: a base URI
- * @uri_string: the URI
- *
- * Parses @uri_string relative to @base.
- *
- * Returns: a parsed #SoupURI.
- **/
-SoupURI *
-soup_uri_new_with_base (SoupURI *base, const char *uri_string)
-{
-       SoupURI *uri, fixed_base;
-       const char *end, *hash, *colon, *at, *path, *question;
-       const char *p, *hostend;
-       gboolean remove_dot_segments = TRUE;
-       int len;
-
-       g_return_val_if_fail (uri_string != NULL, NULL);
-
-       /* Allow a %NULL path in @base, for compatibility */
-       if (base && base->scheme && !base->path) {
-               g_warn_if_fail (SOUP_URI_IS_VALID (base));
-
-               memcpy (&fixed_base, base, sizeof (SoupURI));
-               fixed_base.path = "";
-               base = &fixed_base;
-       }
-
-       g_return_val_if_fail (base == NULL || SOUP_URI_IS_VALID (base), NULL);
-
-       /* First some cleanup steps (which are supposed to all be no-ops,
-        * but...). Skip initial whitespace, strip out internal tabs and
-        * line breaks, and ignore trailing whitespace.
-        */
-       while (g_ascii_isspace (*uri_string))
-               uri_string++;
-
-       len = strcspn (uri_string, "\t\n\r");
-       if (uri_string[len]) {
-               char *clean = g_malloc (strlen (uri_string) + 1), *d;
-               const char *s;
-
-               for (s = uri_string, d = clean; *s; s++) {
-                       if (*s != '\t' && *s != '\n' && *s != '\r')
-                               *d++ = *s;
-               }
-               *d = '\0';
-
-               uri = soup_uri_new_with_base (base, clean);
-               g_free (clean);
-               return uri;
-       }
-       end = uri_string + len;
-       while (end > uri_string && g_ascii_isspace (end[-1]))
-               end--;
-
-       uri = g_slice_new0 (SoupURI);
-
-       /* Find fragment. */
-       hash = strchr (uri_string, '#');
-       if (hash) {
-               uri->fragment = uri_normalized_copy (hash + 1, end - hash + 1,
-                                                    NULL);
-               end = hash;
-       }
-
-       /* Find scheme */
-       p = uri_string;
-       while (p < end && (g_ascii_isalpha (*p) ||
-                          (p > uri_string && (g_ascii_isdigit (*p) ||
-                                              *p == '.' ||
-                                              *p == '+' ||
-                                              *p == '-'))))
-               p++;
-
-       if (p > uri_string && *p == ':') {
-               uri->scheme = soup_uri_parse_scheme (uri_string, p - uri_string);
-               uri_string = p + 1;
-       }
-
-       if (uri_string == end && !base && !uri->fragment) {
-               uri->path = g_strdup ("");
-               return uri;
-        }
-
-       /* Check for authority */
-       if (strncmp (uri_string, "//", 2) == 0) {
-               uri_string += 2;
-
-               path = uri_string + strcspn (uri_string, "/?#");
-               if (path > end)
-                       path = end;
-               at = strchr (uri_string, '@');
-               if (at && at < path) {
-                       colon = strchr (uri_string, ':');
-                       if (colon && colon < at) {
-                               uri->password = soup_uri_decoded_copy (colon + 1,
-                                                                      at - colon - 1, NULL);
-                       } else {
-                               uri->password = NULL;
-                               colon = at;
-                       }
-
-                       uri->user = soup_uri_decoded_copy (uri_string,
-                                                          colon - uri_string, NULL);
-                       uri_string = at + 1;
-               } else
-                       uri->user = uri->password = NULL;
-
-               /* Find host and port. */
-               if (*uri_string == '[') {
-                       const char *pct;
-
-                       uri_string++;
-                       hostend = strchr (uri_string, ']');
-                       if (!hostend || hostend > path) {
-                               soup_uri_free (uri);
-                               return NULL;
-                       }
-                       if (*(hostend + 1) == ':')
-                               colon = hostend + 1;
-                       else
-                               colon = NULL;
-
-                       pct = memchr (uri_string, '%', hostend - uri_string);
-                       if (!pct || (pct[1] == '2' && pct[2] == '5')) {
-                               uri->host = soup_uri_decoded_copy (uri_string,
-                                                                  hostend - uri_string, NULL);
-                       } else
-                               uri->host = g_strndup (uri_string, hostend - uri_string);
-               } else {
-                       colon = memchr (uri_string, ':', path - uri_string);
-                       hostend = colon ? colon : path;
-                       uri->host = soup_uri_decoded_copy (uri_string,
-                                                          hostend - uri_string, NULL);
-               }
-
-               if (colon && colon != path - 1) {
-                       char *portend;
-                       uri->port = strtoul (colon + 1, &portend, 10);
-                       if (portend != (char *)path) {
-                               soup_uri_free (uri);
-                               return NULL;
-                       }
-               }
-
-               uri_string = path;
-       }
-
-       /* Find query */
-       question = memchr (uri_string, '?', end - uri_string);
-       if (question) {
-               uri->query = uri_normalized_copy (question + 1,
-                                                 end - (question + 1),
-                                                 NULL);
-               end = question;
-       }
-
-       if (end != uri_string) {
-               uri->path = uri_normalized_copy (uri_string, end - uri_string,
-                                                NULL);
-       }
-
-       /* Apply base URI. This is spelled out in RFC 3986. */
-       if (base && !uri->scheme && uri->host)
-               uri->scheme = base->scheme;
-       else if (base && !uri->scheme) {
-               uri->scheme = base->scheme;
-               uri->user = g_strdup (base->user);
-               uri->password = g_strdup (base->password);
-               uri->host = g_strdup (base->host);
-               uri->port = base->port;
-
-               if (!uri->path) {
-                       uri->path = g_strdup (base->path);
-                       if (!uri->query)
-                               uri->query = g_strdup (base->query);
-                       remove_dot_segments = FALSE;
-               } else if (*uri->path != '/') {
-                       char *newpath, *last;
-
-                       last = strrchr (base->path, '/');
-                       if (last) {
-                               newpath = g_strdup_printf ("%.*s%s",
-                                                          (int)(last + 1 - base->path),
-                                                          base->path,
-                                                          uri->path);
-                       } else
-                               newpath = g_strdup_printf ("/%s", uri->path);
-
-                       g_free (uri->path);
-                       uri->path = newpath;
-               }
-       }
-
-       if (remove_dot_segments && uri->path && *uri->path) {
-               char *p, *q;
-
-               /* Remove "./" where "." is a complete segment. */
-               for (p = uri->path + 1; *p; ) {
-                       if (*(p - 1) == '/' &&
-                           *p == '.' && *(p + 1) == '/')
-                               memmove (p, p + 2, strlen (p + 2) + 1);
-                       else
-                               p++;
-               }
-               /* Remove "." at end. */
-               if (p > uri->path + 2 &&
-                   *(p - 1) == '.' && *(p - 2) == '/')
-                       *(p - 1) = '\0';
-
-               /* Remove "<segment>/../" where <segment> != ".." */
-               for (p = uri->path + 1; *p; ) {
-                       if (!strncmp (p, "../", 3)) {
-                               p += 3;
-                               continue;
-                       }
-                       q = strchr (p + 1, '/');
-                       if (!q)
-                               break;
-                       if (strncmp (q, "/../", 4) != 0) {
-                               p = q + 1;
-                               continue;
-                       }
-                       memmove (p, q + 4, strlen (q + 4) + 1);
-                       p = uri->path + 1;
-               }
-               /* Remove "<segment>/.." at end where <segment> != ".." */
-               q = strrchr (uri->path, '/');
-               if (q && q != uri->path && !strcmp (q, "/..")) {
-                       p = q - 1;
-                       while (p > uri->path && *p != '/')
-                               p--;
-                       if (strncmp (p, "/../", 4) != 0)
-                               *(p + 1) = 0;
-               }
-
-               /* Remove extraneous initial "/.."s */
-               while (!strncmp (uri->path, "/../", 4))
-                       memmove (uri->path, uri->path + 3, strlen (uri->path) - 2);
-               if (!strcmp (uri->path, "/.."))
-                       uri->path[1] = '\0';
-       }
-
-       /* HTTP-specific stuff */
-       if (uri->scheme == SOUP_URI_SCHEME_HTTP ||
-           uri->scheme == SOUP_URI_SCHEME_HTTPS) {
-               if (!uri->path)
-                       uri->path = g_strdup ("/");
-               if (!SOUP_URI_VALID_FOR_HTTP (uri)) {
-                       soup_uri_free (uri);
-                       return NULL;
-               }
-       }
-
-       if (uri->scheme == SOUP_URI_SCHEME_FTP) {
-               if (!uri->host) {
-                       soup_uri_free (uri);
-                       return NULL;
-               }
-       }
-
-       if (!uri->port)
-               uri->port = soup_scheme_default_port (uri->scheme);
-       if (!uri->path)
-               uri->path = g_strdup ("");
-
-       return uri;
-}
-
-/**
- * soup_uri_new:
- * @uri_string: (allow-none): a URI
- *
- * Parses an absolute URI.
- *
- * You can also pass %NULL for @uri_string if you want to get back an
- * "empty" #SoupURI that you can fill in by hand. (You will need to
- * call at least soup_uri_set_scheme() and soup_uri_set_path(), since
- * those fields are required.)
- *
- * Return value: (nullable): a #SoupURI, or %NULL if the given string
- *  was found to be invalid.
- **/
-SoupURI *
-soup_uri_new (const char *uri_string)
+static inline gboolean
+parts_equal (const char *one, const char *two, gboolean insensitive)
 {
-       SoupURI *uri;
-
-       if (!uri_string)
-               return g_slice_new0 (SoupURI);
-
-       uri = soup_uri_new_with_base (NULL, uri_string);
-       if (!uri)
-               return NULL;
-       if (!SOUP_URI_IS_VALID (uri)) {
-               soup_uri_free (uri);
-               return NULL;
-       }
-
-       return uri;
+       if (!one && !two)
+               return TRUE;
+       if (!one || !two)
+               return FALSE;
+       return insensitive ? !g_ascii_strcasecmp (one, two) : !strcmp (one, two);
 }
 
-
-char *
-soup_uri_to_string_internal (SoupURI *uri, gboolean just_path_and_query,
-                            gboolean include_password, gboolean force_port)
+static inline gboolean
+path_equal (const char *one, const char *two)
 {
-       GString *str;
-       char *return_result;
-
-       g_return_val_if_fail (uri != NULL, NULL);
-       g_warn_if_fail (SOUP_URI_IS_VALID (uri));
-
-       str = g_string_sized_new (40);
-
-       if (uri->scheme && !just_path_and_query)
-               g_string_append_printf (str, "%s:", uri->scheme);
-       if (uri->host && !just_path_and_query) {
-               g_string_append (str, "//");
-               if (uri->user) {
-                       append_uri_encoded (str, uri->user, ":;@?/");
-                       if (uri->password && include_password) {
-                               g_string_append_c (str, ':');
-                               append_uri_encoded (str, uri->password, ";@?/");
-                       }
-                       g_string_append_c (str, '@');
-               }
-               if (strchr (uri->host, ':')) {
-                       const char *pct;
-
-                       g_string_append_c (str, '[');
-                       pct = strchr (uri->host, '%');
-                       if (pct) {
-                               g_string_append_printf (str, "%.*s%%25%s",
-                                                       (int) (pct - uri->host),
-                                                       uri->host, pct + 1);
-                       } else
-                               g_string_append (str, uri->host);
-                       g_string_append_c (str, ']');
-               } else
-                       append_uri_encoded (str, uri->host, ":/");
-               if (uri->port && (force_port || uri->port != soup_scheme_default_port (uri->scheme)))
-                       g_string_append_printf (str, ":%u", uri->port);
-               if (!uri->path && (uri->query || uri->fragment))
-                       g_string_append_c (str, '/');
-               else if ((!uri->path || !*uri->path) &&
-                        (uri->scheme == SOUP_URI_SCHEME_HTTP ||
-                         uri->scheme == SOUP_URI_SCHEME_HTTPS))
-                       g_string_append_c (str, '/');
-       }
+        if (one[0] == '\0')
+                one = "/";
+        if (two[0] == '\0')
+                two = "/";
 
-       if (uri->path && *uri->path)
-               g_string_append (str, uri->path);
-       else if (just_path_and_query)
-               g_string_append_c (str, '/');
-
-       if (uri->query) {
-               g_string_append_c (str, '?');
-               g_string_append (str, uri->query);
-       }
-       if (uri->fragment && !just_path_and_query) {
-               g_string_append_c (str, '#');
-               g_string_append (str, uri->fragment);
-       }
-
-       return_result = str->str;
-       g_string_free (str, FALSE);
-
-       return return_result;
+       return !strcmp (one, two);
 }
 
-/**
- * soup_uri_to_string:
- * @uri: a #SoupURI
- * @just_path_and_query: if %TRUE, output just the path and query portions
- *
- * Returns a string representing @uri.
- *
- * If @just_path_and_query is %TRUE, this concatenates the path and query
- * together. That is, it constructs the string that would be needed in
- * the Request-Line of an HTTP request for @uri.
- *
- * Note that the output will never contain a password, even if @uri
- * does.
- *
- * Return value: a string representing @uri, which the caller must free.
- **/
-char *
-soup_uri_to_string (SoupURI *uri, gboolean just_path_and_query)
-{
-       return soup_uri_to_string_internal (uri, just_path_and_query, FALSE, FALSE);
-}
-
-/**
- * soup_uri_copy:
- * @uri: a #SoupURI
- *
- * Copies @uri
- *
- * Return value: a copy of @uri, which must be freed with soup_uri_free()
- **/
-SoupURI *
-soup_uri_copy (SoupURI *uri)
+int
+soup_uri_get_port_with_default (GUri *uri)
 {
-       SoupURI *dup;
+        int port = g_uri_get_port (uri);
+        if (port != -1)
+                return port;
 
-       g_return_val_if_fail (uri != NULL, NULL);
-       g_warn_if_fail (SOUP_URI_IS_VALID (uri));
-
-       dup = g_slice_new0 (SoupURI);
-       dup->scheme   = uri->scheme;
-       dup->user     = g_strdup (uri->user);
-       dup->password = g_strdup (uri->password);
-       dup->host     = g_strdup (uri->host);
-       dup->port     = uri->port;
-       dup->path     = g_strdup (uri->path);
-       dup->query    = g_strdup (uri->query);
-       dup->fragment = g_strdup (uri->fragment);
-
-       return dup;
-}
-
-static inline gboolean
-parts_equal (const char *one, const char *two, gboolean insensitive)
-{
-       if (!one && !two)
-               return TRUE;
-       if (!one || !two)
-               return FALSE;
-       return insensitive ? !g_ascii_strcasecmp (one, two) : !strcmp (one, two);
+        return soup_scheme_default_port (g_uri_get_scheme (uri));
 }
 
 /**
  * soup_uri_equal:
- * @uri1: a #SoupURI
- * @uri2: another #SoupURI
+ * @uri1: a #GUri
+ * @uri2: another #GUri
  *
  * Tests whether or not @uri1 and @uri2 are equal in all parts
  *
  * Return value: %TRUE or %FALSE
  **/
-gboolean 
-soup_uri_equal (SoupURI *uri1, SoupURI *uri2)
+gboolean
+soup_uri_equal (GUri *uri1, GUri *uri2)
 {
-       g_return_val_if_fail (uri1 != NULL, FALSE);
+       g_return_val_if_fail (uri1 != NULL, FALSE);
        g_return_val_if_fail (uri2 != NULL, FALSE);
-       g_warn_if_fail (SOUP_URI_IS_VALID (uri1));
-       g_warn_if_fail (SOUP_URI_IS_VALID (uri2));
-
-       if (uri1->scheme != uri2->scheme                         ||
-           uri1->port   != uri2->port                           ||
-           !parts_equal (uri1->user, uri2->user, FALSE)         ||
-           !parts_equal (uri1->password, uri2->password, FALSE) ||
-           !parts_equal (uri1->host, uri2->host, TRUE)          ||
-           !parts_equal (uri1->path, uri2->path, FALSE)         ||
-           !parts_equal (uri1->query, uri2->query, FALSE)       ||
-           !parts_equal (uri1->fragment, uri2->fragment, FALSE))
-               return FALSE;
-
-       return TRUE;
-}
 
-/**
- * soup_uri_free:
- * @uri: a #SoupURI
- *
- * Frees @uri.
- **/
-void
-soup_uri_free (SoupURI *uri)
-{
-       g_return_if_fail (uri != NULL);
+               if (!parts_equal (g_uri_get_scheme (uri1), g_uri_get_scheme (uri2), TRUE)          ||
+           soup_uri_get_port_with_default (uri1) != soup_uri_get_port_with_default (uri2) ||
+           !parts_equal (g_uri_get_user (uri1), g_uri_get_user (uri2), FALSE)             ||
+           !parts_equal (g_uri_get_password (uri1), g_uri_get_password (uri2), FALSE)     ||
+           !parts_equal (g_uri_get_host (uri1), g_uri_get_host (uri2), TRUE)              ||
+           !path_equal (g_uri_get_path (uri1), g_uri_get_path (uri2))                     ||
+           !parts_equal (g_uri_get_query (uri1), g_uri_get_query (uri2), FALSE)           ||
+           !parts_equal (g_uri_get_fragment (uri1), g_uri_get_fragment (uri2), FALSE)) {
+                return FALSE;
+            }
 
-       g_free (uri->user);
-       g_free (uri->password);
-       g_free (uri->host);
-       g_free (uri->path);
-       g_free (uri->query);
-       g_free (uri->fragment);
-
-       g_slice_free (SoupURI, uri);
+        return TRUE;
 }
 
+/* This does the "Remove Dot Segments" algorithm from section 5.2.4 of
+ * RFC 3986, except that @path is modified in place.
+ *
+ * See https://tools.ietf.org/html/rfc3986#section-5.2.4
+ */
 static void
-append_uri_encoded (GString *str, const char *in, const char *extra_enc_chars)
-{
-       const unsigned char *s = (const unsigned char *)in;
-
-       while (*s) {
-               if (soup_char_is_uri_percent_encoded (*s) ||
-                   soup_char_is_uri_gen_delims (*s) ||
-                   (extra_enc_chars && strchr (extra_enc_chars, *s)))
-                       g_string_append_printf (str, "%%%02X", (int)*s++);
-               else
-                       g_string_append_c (str, *s++);
-       }
+remove_dot_segments (gchar *path)
+{
+  gchar *p, *q;
+
+  if (!*path)
+    return;
+
+  /* Remove "./" where "." is a complete segment. */
+  for (p = path + 1; *p; )
+    {
+      if (*(p - 1) == '/' &&
+          *p == '.' && *(p + 1) == '/')
+        memmove (p, p + 2, strlen (p + 2) + 1);
+      else
+        p++;
+    }
+  /* Remove "." at end. */
+  if (p > path + 2 &&
+      *(p - 1) == '.' && *(p - 2) == '/')
+    *(p - 1) = '\0';
+
+  /* Remove "<segment>/../" where <segment> != ".." */
+  for (p = path + 1; *p; )
+    {
+      if (!strncmp (p, "../", 3))
+        {
+          p += 3;
+          continue;
+        }
+      q = strchr (p + 1, '/');
+      if (!q)
+        break;
+      if (strncmp (q, "/../", 4) != 0)
+        {
+          p = q + 1;
+          continue;
+        }
+      memmove (p, q + 4, strlen (q + 4) + 1);
+      p = path + 1;
+    }
+  /* Remove "<segment>/.." at end where <segment> != ".." */
+  q = strrchr (path, '/');
+  if (q && q != path && !strcmp (q, "/.."))
+    {
+      p = q - 1;
+      while (p > path && *p != '/')
+        p--;
+      if (strncmp (p, "/../", 4) != 0)
+        *(p + 1) = 0;
+    }
+
+  /* Remove extraneous initial "/.."s */
+  while (!strncmp (path, "/../", 4))
+    memmove (path, path + 3, strlen (path) - 2);
+  if (!strcmp (path, "/.."))
+    path[1] = '\0';
 }
 
-/**
- * soup_uri_encode:
- * @part: a URI part
- * @escape_extra: (allow-none): additional reserved characters to
- * escape (or %NULL)
- *
- * This %<!-- -->-encodes the given URI part and returns the escaped
- * version in allocated memory, which the caller must free when it is
- * done.
- *
- * Return value: the encoded URI part
- **/
 char *
-soup_uri_encode (const char *part, const char *escape_extra)
+soup_uri_get_path_and_query (GUri *uri)
 {
-       GString *str;
-       char *encoded;
-
-       g_return_val_if_fail (part != NULL, NULL);
-
-       str = g_string_new (NULL);
-       append_uri_encoded (str, part, escape_extra);
-       encoded = str->str;
-       g_string_free (str, FALSE);
+       g_return_val_if_fail (uri != NULL, NULL);
 
-       return encoded;
+       return g_uri_join_with_user (SOUP_HTTP_URI_FLAGS,
+                                    NULL, NULL, NULL, NULL, NULL, -1,
+                                    g_uri_get_path (uri),
+                                    g_uri_get_query (uri),
+                                    NULL);
 }
 
 #define XDIGIT(c) ((c) <= '9' ? (c) - '0' : ((c) & 0x4F) - 'A' + 10)
 #define HEXCHAR(s) ((XDIGIT (s[1]) << 4) + XDIGIT (s[2]))
 
-/* length must be set (e.g. from strchr()) such that [part, part + length]
- * contains no nul bytes */
-char *
-soup_uri_decoded_copy (const char *part, int length, int *decoded_length)
-{
-       unsigned char *s, *d;
-       char *decoded;
-
-       g_return_val_if_fail (part != NULL, NULL);
-
-       decoded = g_strndup (part, length);
-       s = d = (unsigned char *)decoded;
-       do {
-               if (*s == '%') {
-                       if (s[1] == '\0' ||
-                           s[2] == '\0' ||
-                           !g_ascii_isxdigit (s[1]) ||
-                           !g_ascii_isxdigit (s[2])) {
-                               *d++ = *s;
-                               continue;
-                       }
-                       *d++ = HEXCHAR (s);
-                       s += 2;
-               } else
-                       *d++ = *s;
-       } while (*s++);
-
-       if (decoded_length)
-               *decoded_length = d - (unsigned char *)decoded - 1;
-
-       return decoded;
-}
-
-/**
- * soup_uri_decode:
- * @part: a URI part
- *
- * Fully %<!-- -->-decodes @part.
- *
- * In the past, this would return %NULL if @part contained invalid
- * percent-encoding, but now it just ignores the problem (as
- * soup_uri_new() already did).
- *
- * Return value: the decoded URI part.
- */
-char *
-soup_uri_decode (const char *part)
-{
-       g_return_val_if_fail (part != NULL, NULL);
-
-       return soup_uri_decoded_copy (part, strlen (part), NULL);
-}
-
 /* length must be set (e.g. from strchr()) such that [part, part + length]
  * contains no nul bytes */
 static char *
@@ -910,7 +273,7 @@ soup_uri_normalize (const char *part, const char *unescape_extra)
 
 /**
  * soup_uri_uses_default_port:
- * @uri: a #SoupURI
+ * @uri: a #GUri
  *
  * Tests if @uri uses the default port for its scheme. (Eg, 80 for
  * http.) (This only works for http, https and ftp; libsoup does not know
@@ -919,287 +282,53 @@ soup_uri_normalize (const char *part, const char *unescape_extra)
  * Return value: %TRUE or %FALSE
  **/
 gboolean
-soup_uri_uses_default_port (SoupURI *uri)
-{
-       g_return_val_if_fail (uri != NULL, FALSE);
-       g_warn_if_fail (SOUP_URI_IS_VALID (uri));
-
-       return uri->port == soup_scheme_default_port (uri->scheme);
-}
-
-/**
- * soup_uri_get_scheme:
- * @uri: a #SoupURI
- *
- * Gets @uri's scheme.
- *
- * Return value: @uri's scheme.
- *
- * Since: 2.32
- **/
-const char *
-soup_uri_get_scheme (SoupURI *uri)
-{
-       g_return_val_if_fail (uri != NULL, NULL);
-
-       return uri->scheme;
-}
-
-/**
- * soup_uri_set_scheme:
- * @uri: a #SoupURI
- * @scheme: the URI scheme
- *
- * Sets @uri's scheme to @scheme. This will also set @uri's port to
- * the default port for @scheme, if known.
- **/
-void
-soup_uri_set_scheme (SoupURI *uri, const char *scheme)
-{
-       g_return_if_fail (uri != NULL);
-       g_return_if_fail (scheme != NULL);
-
-       uri->scheme = soup_uri_parse_scheme (scheme, strlen (scheme));
-       uri->port = soup_scheme_default_port (uri->scheme);
-}
-
-/**
- * soup_uri_get_user:
- * @uri: a #SoupURI
- *
- * Gets @uri's user.
- *
- * Return value: @uri's user.
- *
- * Since: 2.32
- **/
-const char *
-soup_uri_get_user (SoupURI *uri)
-{
-       g_return_val_if_fail (uri != NULL, NULL);
-
-       return uri->user;
-}
-
-/**
- * soup_uri_set_user:
- * @uri: a #SoupURI
- * @user: (allow-none): the username, or %NULL
- *
- * Sets @uri's user to @user.
- **/
-void
-soup_uri_set_user (SoupURI *uri, const char *user)
-{
-       g_return_if_fail (uri != NULL);
-
-       g_free (uri->user);
-       uri->user = g_strdup (user);
-}
-
-/**
- * soup_uri_get_password:
- * @uri: a #SoupURI
- *
- * Gets @uri's password.
- *
- * Return value: @uri's password.
- *
- * Since: 2.32
- **/
-const char *
-soup_uri_get_password (SoupURI *uri)
-{
-       g_return_val_if_fail (uri != NULL, NULL);
-
-       return uri->password;
-}
-
-/**
- * soup_uri_set_password:
- * @uri: a #SoupURI
- * @password: (allow-none): the password, or %NULL
- *
- * Sets @uri's password to @password.
- **/
-void
-soup_uri_set_password (SoupURI *uri, const char *password)
-{
-       g_return_if_fail (uri != NULL);
-
-       g_free (uri->password);
-       uri->password = g_strdup (password);
-}
-
-/**
- * soup_uri_get_host:
- * @uri: a #SoupURI
- *
- * Gets @uri's host.
- *
- * Return value: @uri's host.
- *
- * Since: 2.32
- **/
-const char *
-soup_uri_get_host (SoupURI *uri)
-{
-       g_return_val_if_fail (uri != NULL, NULL);
-
-       return uri->host;
-}
-
-/**
- * soup_uri_set_host:
- * @uri: a #SoupURI
- * @host: (allow-none): the hostname or IP address, or %NULL
- *
- * Sets @uri's host to @host.
- *
- * If @host is an IPv6 IP address, it should not include the brackets
- * required by the URI syntax; they will be added automatically when
- * converting @uri to a string.
- *
- * http and https URIs should not have a %NULL @host.
- **/
-void
-soup_uri_set_host (SoupURI *uri, const char *host)
-{
-       g_return_if_fail (uri != NULL);
-
-       g_free (uri->host);
-       uri->host = g_strdup (host);
-}
-
-/**
- * soup_uri_get_port:
- * @uri: a #SoupURI
- *
- * Gets @uri's port.
- *
- * Return value: @uri's port.
- *
- * Since: 2.32
- **/
-guint
-soup_uri_get_port (SoupURI *uri)
-{
-       g_return_val_if_fail (uri != NULL, 0);
-
-       return uri->port;
-}
-
-/**
- * soup_uri_set_port:
- * @uri: a #SoupURI
- * @port: the port, or 0
- *
- * Sets @uri's port to @port. If @port is 0, @uri will not have an
- * explicitly-specified port.
- **/
-void
-soup_uri_set_port (SoupURI *uri, guint port)
-{
-       g_return_if_fail (uri != NULL);
-
-       uri->port = port;
-}
-
-/**
- * soup_uri_get_path:
- * @uri: a #SoupURI
- *
- * Gets @uri's path.
- *
- * Return value: @uri's path.
- *
- * Since: 2.32
- **/
-const char *
-soup_uri_get_path (SoupURI *uri)
-{
-       g_return_val_if_fail (uri != NULL, NULL);
-
-       return uri->path;
-}
-
-/**
- * soup_uri_set_path:
- * @uri: a #SoupURI
- * @path: the non-%NULL path
- *
- * Sets @uri's path to @path.
- **/
-void
-soup_uri_set_path (SoupURI *uri, const char *path)
-{
-       g_return_if_fail (uri != NULL);
-
-       /* We allow a NULL path for compatibility, but warn about it. */
-       if (!path) {
-               g_warn_if_fail (path != NULL);
-               path = "";
-       }
-
-       g_free (uri->path);
-       uri->path = g_strdup (path);
-}
-
-/**
- * soup_uri_get_query:
- * @uri: a #SoupURI
- *
- * Gets @uri's query.
- *
- * Return value: @uri's query.
- *
- * Since: 2.32
- **/
-const char *
-soup_uri_get_query (SoupURI *uri)
+soup_uri_uses_default_port (GUri *uri)
 {
-       g_return_val_if_fail (uri != NULL, NULL);
+        g_return_val_if_fail (uri != NULL, FALSE);
 
-       return uri->query;
+        return g_uri_get_port (uri) == soup_scheme_default_port (g_uri_get_scheme (uri));
 }
 
-/**
- * soup_uri_set_query:
- * @uri: a #SoupURI
- * @query: (allow-none): the query
- *
- * Sets @uri's query to @query.
- **/
-void
-soup_uri_set_query (SoupURI *uri, const char *query)
+static GUri *
+soup_uri_copy_with_query (GUri *uri, const char *query)
 {
-       g_return_if_fail (uri != NULL);
-
-       g_free (uri->query);
-       uri->query = g_strdup (query);
+        return g_uri_build_with_user (
+                g_uri_get_flags (uri) | G_URI_FLAGS_ENCODED_QUERY,
+                g_uri_get_scheme (uri),
+                g_uri_get_user (uri),
+                g_uri_get_password (uri),
+                g_uri_get_auth_params (uri),
+                g_uri_get_host (uri),
+                g_uri_get_port (uri),
+                g_uri_get_path (uri),
+                query,
+                g_uri_get_fragment (uri)
+        );
 }
 
 /**
- * soup_uri_set_query_from_form:
- * @uri: a #SoupURI
+ * soup_uri_copy_with_query_from_form:
+ * @uri: a #GUri
  * @form: (element-type utf8 utf8): a #GHashTable containing HTML form
  * information
  *
  * Sets @uri's query to the result of encoding @form according to the
  * HTML form rules. See soup_form_encode_hash() for more information.
  **/
-void
-soup_uri_set_query_from_form (SoupURI *uri, GHashTable *form)
+GUri *
+soup_uri_copy_with_query_from_form (GUri *uri, GHashTable *form)
 {
-       g_return_if_fail (uri != NULL);
+       g_return_val_if_fail (uri != NULL, NULL);
 
-       g_free (uri->query);
-       uri->query = soup_form_encode_hash (form);
+        char *query = soup_form_encode_hash (form);
+       GUri *new_uri = soup_uri_copy_with_query (uri, query);
+        g_free (query);
+       return new_uri;
 }
 
 /**
  * soup_uri_set_query_from_fields:
- * @uri: a #SoupURI
+ * @uri: a #GUri
  * @first_field: name of the first form field to encode into query
  * @...: value of @first_field, followed by additional field names
  * and values, terminated by %NULL.
@@ -1208,85 +337,49 @@ soup_uri_set_query_from_form (SoupURI *uri, GHashTable *form)
  * and values according to the * HTML form rules. See
  * soup_form_encode() for more information.
  **/
-void
-soup_uri_set_query_from_fields (SoupURI    *uri,
-                               const char *first_field,
-                               ...)
+GUri *
+soup_uri_copy_with_query_from_fields (GUri       *uri,
+                                      const char *first_field,
+                                      ...)
 {
        va_list args;
 
-       g_return_if_fail (uri != NULL);
+       g_return_val_if_fail (uri != NULL, NULL);
 
-       g_free (uri->query);
        va_start (args, first_field);
-       uri->query = soup_form_encode_valist (first_field, args);
+       char *query = soup_form_encode_valist (first_field, args);
        va_end (args);
-}
-
-/**
- * soup_uri_get_fragment:
- * @uri: a #SoupURI
- *
- * Gets @uri's fragment.
- *
- * Return value: @uri's fragment.
- *
- * Since: 2.32
- **/
-const char *
-soup_uri_get_fragment (SoupURI *uri)
-{
-       g_return_val_if_fail (uri != NULL, NULL);
-
-       return uri->fragment;
-}
-
-/**
- * soup_uri_set_fragment:
- * @uri: a #SoupURI
- * @fragment: (allow-none): the fragment
- *
- * Sets @uri's fragment to @fragment.
- **/
-void
-soup_uri_set_fragment (SoupURI *uri, const char *fragment)
-{
-       g_return_if_fail (uri != NULL);
 
-       g_free (uri->fragment);
-       uri->fragment = g_strdup (fragment);
+       GUri *new_uri = soup_uri_copy_with_query (uri, query);
+        g_free (query);
+       return new_uri;
 }
 
 /**
  * soup_uri_copy_host:
- * @uri: a #SoupURI
+ * @uri: a #GUri
  *
  * Makes a copy of @uri, considering only the protocol, host, and port
  *
- * Return value: the new #SoupURI
+ * Return value: the new #GUri
  *
  * Since: 2.28
  **/
-SoupURI *
-soup_uri_copy_host (SoupURI *uri)
+GUri *
+soup_uri_copy_host (GUri *uri)
 {
-       SoupURI *dup;
-
-       g_return_val_if_fail (uri != NULL, NULL);
-       g_warn_if_fail (SOUP_URI_IS_VALID (uri));
-
-       dup = soup_uri_new (NULL);
-       dup->scheme = uri->scheme;
-       dup->host   = g_strdup (uri->host);
-       dup->port   = uri->port;
-       dup->path   = g_strdup ("");
+        g_return_val_if_fail (uri != NULL, NULL);
 
-       return dup;
+        return g_uri_build (g_uri_get_flags (uri),
+                            g_uri_get_scheme (uri), NULL,
+                            g_uri_get_host (uri),
+                            g_uri_get_port (uri),
+                            "/", NULL, NULL);
 }
 
 /**
  * soup_uri_host_hash:
- * @key: (type Soup.URI): a #SoupURI with a non-%NULL @host member
+ * @key: (type GUri): a #GUri with a non-%NULL @host member
  *
  * Hashes @key, considering only the scheme, host, and port.
  *
@@ -1297,19 +390,24 @@ soup_uri_copy_host (SoupURI *uri)
 guint
 soup_uri_host_hash (gconstpointer key)
 {
-       const SoupURI *uri = key;
+       GUri *uri = (GUri*)key;
+        const char *host;
+
+       g_return_val_if_fail (uri != NULL, 0);
 
-       g_return_val_if_fail (uri != NULL && uri->host != NULL, 0);
-       g_warn_if_fail (SOUP_URI_IS_VALID (uri));
+        host = g_uri_get_host (uri);
 
-       return GPOINTER_TO_UINT (uri->scheme) + uri->port +
-               soup_str_case_hash (uri->host);
+       g_return_val_if_fail (host != NULL, 0);
+
+       return soup_str_case_hash (g_uri_get_scheme (uri)) +
+               g_uri_get_port (uri) +
+              soup_str_case_hash (host);
 }
 
 /**
  * soup_uri_host_equal:
- * @v1: (type Soup.URI): a #SoupURI with a non-%NULL @host member
- * @v2: (type Soup.URI): a #SoupURI with a non-%NULL @host member
+ * @v1: (type GUri): a #GUri with a non-%NULL @host member
+ * @v2: (type GUri): a #GUri with a non-%NULL @host member
  *
  * Compares @v1 and @v2, considering only the scheme, host, and port.
  *
@@ -1321,38 +419,54 @@ soup_uri_host_hash (gconstpointer key)
 gboolean
 soup_uri_host_equal (gconstpointer v1, gconstpointer v2)
 {
-       const SoupURI *one = v1;
-       const SoupURI *two = v2;
+       GUri *one = (GUri*)v1;
+       GUri *two = (GUri*)v2;
+        const char *one_host, *two_host;
+        int one_port, two_port;
 
        g_return_val_if_fail (one != NULL && two != NULL, one == two);
-       g_return_val_if_fail (one->host != NULL && two->host != NULL, one->host == two->host);
-       g_warn_if_fail (SOUP_URI_IS_VALID (one));
-       g_warn_if_fail (SOUP_URI_IS_VALID (two));
 
-       if (one->scheme != two->scheme)
+        one_host = g_uri_get_host (one);
+        two_host = g_uri_get_host (two);
+
+       g_return_val_if_fail (one_host != NULL && two_host != NULL, one_host == two_host);
+
+        if (one == two)
+                return TRUE;
+       if (!g_ascii_strcasecmp (g_uri_get_scheme (one), g_uri_get_scheme (two)))
                return FALSE;
-       if (one->port != two->port)
+
+        one_port = g_uri_get_port (one);
+        two_port = g_uri_get_port (two);
+
+        // FIXME
+        // if (one_port == -1)
+        //         one_port = soup_scheme_default_port (g_uri_get_scheme (one));
+        // if (two_port == -1)
+        //         two_port = soup_scheme_default_port (g_uri_get_scheme (two));
+
+       if (one_port != two_port)
                return FALSE;
 
-       return g_ascii_strcasecmp (one->host, two->host) == 0;
+        // QUESTION: Used to just be a string comparison?
+       return soup_host_matches_host (one_host, two_host);
 }
 
 gboolean
-soup_uri_is_http (SoupURI *uri, char **aliases)
+soup_uri_is_https (GUri *uri, char **aliases)
 {
-       int i;
+       g_return_val_if_fail (uri != NULL, FALSE);
 
-       if (uri->scheme == SOUP_URI_SCHEME_HTTP ||
-           uri->scheme == SOUP_URI_SCHEME_WS)
-               return TRUE;
-       else if (uri->scheme == SOUP_URI_SCHEME_HTTPS ||
-                uri->scheme == SOUP_URI_SCHEME_WSS)
-               return FALSE;
+        const char *scheme = g_uri_get_scheme (uri);
+
+        if (!g_ascii_strcasecmp (scheme, "https") ||
+            !g_ascii_strcasecmp (scheme, "wss"))
+            return TRUE;
        else if (!aliases)
                return FALSE;
 
-       for (i = 0; aliases[i]; i++) {
-               if (uri->scheme == aliases[i])
+       for (int i = 0; aliases[i]; i++) {
+               if (!g_ascii_strcasecmp (scheme, aliases[i]))
                        return TRUE;
        }
 
@@ -1360,25 +474,278 @@ soup_uri_is_http (SoupURI *uri, char **aliases)
 }
 
 gboolean
-soup_uri_is_https (SoupURI *uri, char **aliases)
+soup_uri_is_http (GUri *uri, char **aliases)
 {
-       int i;
+       g_return_val_if_fail (uri != NULL, FALSE);
 
-       if (uri->scheme == SOUP_URI_SCHEME_HTTPS ||
-           uri->scheme == SOUP_URI_SCHEME_WSS)
-               return TRUE;
-       else if (uri->scheme == SOUP_URI_SCHEME_HTTP ||
-                uri->scheme == SOUP_URI_SCHEME_WS)
-               return FALSE;
+        const char *scheme = g_uri_get_scheme (uri);
+
+        if (!g_ascii_strcasecmp (scheme, "http") ||
+            !g_ascii_strcasecmp (scheme, "ws"))
+            return TRUE;
        else if (!aliases)
                return FALSE;
 
-       for (i = 0; aliases[i]; i++) {
-               if (uri->scheme == aliases[i])
+       for (int i = 0; aliases[i]; i++) {
+               if (!g_ascii_strcasecmp (scheme, aliases[i]))
                        return TRUE;
        }
 
        return FALSE;
 }
 
-G_DEFINE_BOXED_TYPE (SoupURI, soup_uri, soup_uri_copy, soup_uri_free)
+gboolean
+soup_uri_valid_for_http (GUri *uri, GError **error)
+{
+        if (G_UNLIKELY (!uri)) {
+                g_set_error_literal (error, SOUP_REQUEST_ERROR, SOUP_REQUEST_ERROR_BAD_URI, "URI is NULL");
+                return FALSE;
+        }
+
+        const char *scheme = g_uri_get_scheme (uri);
+        // QUESITON: Accept any scheme?
+        if (G_UNLIKELY (!(!g_ascii_strcasecmp (scheme, "https") ||
+                          !g_ascii_strcasecmp (scheme, "http")))) {
+                g_set_error (error, SOUP_REQUEST_ERROR, SOUP_REQUEST_ERROR_BAD_URI, "URI has invalid scheme: 
%s", scheme);
+                return FALSE;
+        }
+
+        const char *host = g_uri_get_host (uri);
+        if (G_UNLIKELY (!host && !*host)) {
+                g_set_error_literal (error, SOUP_REQUEST_ERROR, SOUP_REQUEST_ERROR_BAD_URI, "URI missing 
host");
+                return FALSE;
+        }
+
+        return TRUE;
+}
+
+GUri *
+soup_uri_copy_with_credentials (GUri *uri, const char *username, const char *password)
+{
+        g_return_val_if_fail (uri != NULL, NULL);
+
+        return g_uri_build_with_user (
+                g_uri_get_flags (uri) | G_URI_FLAGS_HAS_PASSWORD,
+                g_uri_get_scheme (uri),
+                username, password,
+                g_uri_get_auth_params (uri),
+                g_uri_get_host (uri),
+                g_uri_get_port (uri),
+                g_uri_get_path (uri),
+                g_uri_get_query (uri),
+                g_uri_get_fragment (uri)
+        );
+}
+
+gboolean
+soup_uri_paths_equal (const char *path1, const char *path2, gssize len)
+{
+        g_return_val_if_fail (path1 != NULL, path1 == path2);
+        g_return_val_if_fail (path2 != NULL, path1 == path2);
+
+        if (path1[0] == '\0')
+                path1 = "/";
+        if (path2[0] == '\0')
+                path2 = "/";
+
+        if (len == -1)
+                return g_ascii_strcasecmp (path1, path2) == 0;
+        else
+                return g_ascii_strncasecmp (path1, path2, len) == 0;
+}
+
+static inline gboolean
+is_string_normalized (const char *str)
+{
+        if (str == NULL)
+                return TRUE;
+
+        const char *s = str;
+        while (*s) {
+               if (*s == '%') {
+                        /* Check for invalid escapes */
+                       if (s[1] == '\0' ||
+                           s[2] == '\0' ||
+                           !g_ascii_isxdigit (s[1]) ||
+                           !g_ascii_isxdigit (s[2]))
+                                return FALSE;
+                       else
+                                s += 3;
+               } else {
+                        /* Check for invalid characters */
+                       if (!g_ascii_isgraph (*s))
+                                return FALSE;
+                        s++;
+               }
+        }
+
+        return TRUE;
+}
+
+static inline gboolean
+is_string_lower (const char *str)
+{
+        if (str == NULL)
+                return TRUE;
+
+        const char *s = str;
+        while (*s) {
+                if (!g_ascii_islower (*s))
+                        return FALSE;
+                s++;
+        }
+
+        return TRUE;
+}
+
+GUri *
+soup_uri_parse_normalized (GUri *base, const char *uri_string, GError **error)
+{
+        char *scheme, *user, *password, *auth_params, *host, *path, *query, *fragment;
+        int port;
+
+        g_return_val_if_fail (uri_string != NULL, NULL);
+
+        if (!g_uri_split_with_user  (uri_string, SOUP_HTTP_URI_FLAGS,
+                                     &scheme, &user, &password, &auth_params,
+                                     &host, &port,
+                                     &path, &query, &fragment, error))
+                return NULL;
+
+        char *normalized_path, *normalized_query, *normalized_fragment;
+        normalized_path = path ? soup_uri_normalize (path, FALSE) : NULL;
+        normalized_query = query ? soup_uri_normalize (query, FALSE) : NULL;
+        normalized_fragment = fragment ? soup_uri_normalize (fragment, FALSE) : NULL;
+        remove_dot_segments (normalized_path);
+
+        if (scheme && port == soup_scheme_default_port (scheme))
+                port = -1;
+
+        if (!is_string_lower (scheme)) {
+                char *lower_scheme = g_ascii_strdown (scheme, -1); // TODO: Lower in-place?
+                g_free (scheme);
+                scheme = g_steal_pointer (&lower_scheme);
+        }
+
+        char *normalized_uri_string = g_uri_join_with_user (SOUP_HTTP_URI_FLAGS,
+                                                            scheme, user, password, auth_params,
+                                                            host, port, normalized_path,
+                                                            normalized_query, normalized_fragment);
+
+        g_free (scheme);
+        g_free (user);
+        g_free (password);
+        g_free (auth_params);
+        g_free (host);
+        g_free (path);
+        g_free (query);
+        g_free (fragment);
+        g_free (normalized_path);
+        g_free (normalized_query);
+        g_free (normalized_fragment);
+
+        GUri *normalized_uri = g_uri_parse_relative (base, normalized_uri_string, SOUP_HTTP_URI_FLAGS, 
error);
+        g_free (normalized_uri_string);
+        return normalized_uri;
+}
+
+typedef enum {
+        SOUP_NORMALIZE_FLAG_DEFAULT = 0,
+        SOUP_NORMALISE_FLAG_PORT = (1 << 0),
+} SoupNormalizeFlags;
+
+static GUri *
+soup_normalize_uri_internal (GUri *uri, SoupNormalizeFlags flags)
+{
+        const char *scheme, *path, *query, *fragment;
+        int port;
+
+        scheme = g_uri_get_scheme (uri);
+        path = g_uri_get_path (uri);
+        query = g_uri_get_query (uri);
+        fragment = g_uri_get_fragment (uri);
+        port = g_uri_get_port (uri);
+
+        char *normalized_scheme = NULL, *normalized_path = NULL, *normalized_query = NULL, 
*normalized_fragment = NULL;
+        int normalized_port = 0;
+
+        if (!is_string_lower (scheme)) {
+                normalized_scheme = g_ascii_strdown (scheme, -1);
+                scheme = normalized_scheme;
+        }
+
+        /* If the path isn't escaped we always escape it */
+        if (!(g_uri_get_flags (uri) & G_URI_FLAGS_ENCODED_PATH))
+                normalized_path = g_uri_escape_string (path, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, FALSE);
+        /* If it is escaped we ensure its valid */
+        else if (!is_string_normalized (path))
+                normalized_path = uri_normalized_copy (path, strlen (path), NULL);
+        else if (path[0] == '\0' &&
+                 (!g_strcmp0 (scheme, "http") || !g_strcmp0 (scheme, "https")))
+                normalized_path = g_strdup ("/");
+
+        /* Roughly guess if we need to remove dots */
+        if (strstr (path, "/.")) {
+                if (!normalized_path)
+                        normalized_path = g_strdup (path);
+                remove_dot_segments (normalized_path);
+        }
+
+        if (!(g_uri_get_flags (uri) & G_URI_FLAGS_ENCODED_QUERY))
+                normalized_query = g_uri_escape_string (query, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, FALSE);
+        else if (!is_string_normalized (query))
+                normalized_query = uri_normalized_copy (query, strlen (query), NULL);
+
+        if (!(g_uri_get_flags (uri) & G_URI_FLAGS_ENCODED_FRAGMENT))
+                normalized_fragment = g_uri_escape_string (fragment, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, 
FALSE);
+        else if (!is_string_normalized (fragment))
+                normalized_fragment = uri_normalized_copy (fragment, strlen (fragment), NULL);
+
+        if (flags & SOUP_NORMALISE_FLAG_PORT && scheme != NULL &&
+            port != -1 && port == soup_scheme_default_port (normalized_scheme ? normalized_scheme : scheme))
+                normalized_port = -1;
+
+        if (normalized_scheme || normalized_path || normalized_query || normalized_fragment || 
normalized_port) {
+                GUri *normalized_uri = g_uri_build_with_user (
+                        g_uri_get_flags (uri) | G_URI_FLAGS_ENCODED_PATH | G_URI_FLAGS_ENCODED_QUERY | 
G_URI_FLAGS_ENCODED_FRAGMENT,
+                        normalized_scheme ? normalized_scheme : scheme,
+                        g_uri_get_user (uri),
+                        g_uri_get_password (uri),
+                        g_uri_get_auth_params (uri),
+                        g_uri_get_host (uri),
+                        normalized_port ? normalized_port : port,
+                        normalized_path ? normalized_path : path,
+                        normalized_query ? normalized_query : query,
+                        normalized_fragment ? normalized_fragment : fragment
+                );
+
+                g_free (normalized_scheme);
+                g_free (normalized_path);
+                g_free (normalized_query);
+                g_free (normalized_fragment);
+
+                return normalized_uri;
+        }
+
+        return g_uri_ref (uri);
+}
+
+#if 0
+GUri *
+soup_normalize_uri_take (GUri *uri)
+{
+        g_return_val_if_fail (uri != NULL, NULL);
+
+        GUri *new_uri = soup_normalize_uri_internal (uri, SOUP_NORMALIZE_FLAG_DEFAULT);
+        g_uri_unref (uri);
+        return new_uri;
+}
+#endif
+
+GUri *
+soup_normalize_uri (GUri *uri)
+{
+        g_return_val_if_fail (uri != NULL, NULL);
+
+        return soup_normalize_uri_internal (uri, SOUP_NORMALIZE_FLAG_DEFAULT);
+}
diff --git a/libsoup/soup-uri.h b/libsoup/soup-uri.h
index 6e949ea1..d5d3e187 100644
--- a/libsoup/soup-uri.h
+++ b/libsoup/soup-uri.h
@@ -11,130 +11,57 @@
 
 G_BEGIN_DECLS
 
-struct _SoupURI {
-       const char *scheme;
-
-       char       *user;
-       char       *password;
-
-       char       *host;
-       guint       port;
-
-       char       *path;
-       char       *query;
-
-       char       *fragment;
-};
-
 SOUP_AVAILABLE_IN_2_4
-GType       soup_uri_get_type              (void);
-#define SOUP_TYPE_URI (soup_uri_get_type ())
-
-#define SOUP_URI_SCHEME_HTTP     _SOUP_ATOMIC_INTERN_STRING (_SOUP_URI_SCHEME_HTTP, "http")
-#define SOUP_URI_SCHEME_HTTPS    _SOUP_ATOMIC_INTERN_STRING (_SOUP_URI_SCHEME_HTTPS, "https")
-#define SOUP_URI_SCHEME_FTP      _SOUP_ATOMIC_INTERN_STRING (_SOUP_URI_SCHEME_FTP, "ftp")
-#define SOUP_URI_SCHEME_FILE     _SOUP_ATOMIC_INTERN_STRING (_SOUP_URI_SCHEME_FILE, "file")
-#define SOUP_URI_SCHEME_DATA     _SOUP_ATOMIC_INTERN_STRING (_SOUP_URI_SCHEME_DATA, "data")
-#define SOUP_URI_SCHEME_RESOURCE _SOUP_ATOMIC_INTERN_STRING (_SOUP_URI_SCHEME_RESOURCE, "resource")
-#define SOUP_URI_SCHEME_WS       _SOUP_ATOMIC_INTERN_STRING (_SOUP_URI_SCHEME_WS, "ws")
-#define SOUP_URI_SCHEME_WSS      _SOUP_ATOMIC_INTERN_STRING (_SOUP_URI_SCHEME_WSS, "wss")
-
-SOUP_VAR gpointer _SOUP_URI_SCHEME_HTTP, _SOUP_URI_SCHEME_HTTPS;
-SOUP_VAR gpointer _SOUP_URI_SCHEME_FTP;
-SOUP_VAR gpointer _SOUP_URI_SCHEME_FILE, _SOUP_URI_SCHEME_DATA, _SOUP_URI_SCHEME_RESOURCE;
-SOUP_VAR gpointer _SOUP_URI_SCHEME_WS, _SOUP_URI_SCHEME_WSS;
+GUri *soup_uri_parse_normalized (GUri *base, const char *uri_string, GError **error);
 
 SOUP_AVAILABLE_IN_2_4
-SoupURI           *soup_uri_new_with_base         (SoupURI    *base,
-                                           const char *uri_string);
-SOUP_AVAILABLE_IN_2_4
-SoupURI           *soup_uri_new                   (const char *uri_string);
+char       *soup_uri_get_path_and_query    (GUri       *uri);
 
 SOUP_AVAILABLE_IN_2_4
-char              *soup_uri_to_string             (SoupURI    *uri,
-                                           gboolean    just_path_and_query);
+GUri       *soup_uri_copy_host            (GUri       *uri);
 
 SOUP_AVAILABLE_IN_2_4
-SoupURI           *soup_uri_copy                  (SoupURI    *uri);
+guint       soup_uri_host_hash (gconstpointer key);
 
 SOUP_AVAILABLE_IN_2_4
-gboolean    soup_uri_equal                 (SoupURI    *uri1,
-                                           SoupURI    *uri2);
+gboolean    soup_uri_host_equal (gconstpointer v1, gconstpointer v2);
 
 SOUP_AVAILABLE_IN_2_4
-void       soup_uri_free                  (SoupURI    *uri);
+gboolean soup_uri_equal (GUri *uri1, GUri *uri2);
 
 SOUP_AVAILABLE_IN_2_4
-char      *soup_uri_encode                (const char *part,
-                                           const char *escape_extra);
-SOUP_AVAILABLE_IN_2_4
-char      *soup_uri_decode                (const char *part);
-SOUP_AVAILABLE_IN_2_4
-char      *soup_uri_normalize             (const char *part,
-                                           const char *unescape_extra);
+gboolean soup_uri_is_http (GUri *uri, char **aliases);
 
 SOUP_AVAILABLE_IN_2_4
-gboolean    soup_uri_uses_default_port     (SoupURI    *uri);
+gboolean soup_uri_is_https (GUri *uri, char **aliases);
 
-SOUP_AVAILABLE_IN_2_32
-const char *soup_uri_get_scheme            (SoupURI    *uri);
-SOUP_AVAILABLE_IN_2_4
-void        soup_uri_set_scheme            (SoupURI    *uri,
-                                           const char *scheme);
-SOUP_AVAILABLE_IN_2_32
-const char *soup_uri_get_user              (SoupURI    *uri);
-SOUP_AVAILABLE_IN_2_4
-void        soup_uri_set_user              (SoupURI    *uri,
-                                           const char *user);
-SOUP_AVAILABLE_IN_2_32
-const char *soup_uri_get_password          (SoupURI    *uri);
 SOUP_AVAILABLE_IN_2_4
-void        soup_uri_set_password          (SoupURI    *uri,
-                                           const char *password);
-SOUP_AVAILABLE_IN_2_32
-const char *soup_uri_get_host              (SoupURI    *uri);
-SOUP_AVAILABLE_IN_2_4
-void        soup_uri_set_host              (SoupURI    *uri,
-                                           const char *host);
-SOUP_AVAILABLE_IN_2_32
-guint       soup_uri_get_port              (SoupURI    *uri);
-SOUP_AVAILABLE_IN_2_4
-void        soup_uri_set_port              (SoupURI    *uri,
-                                           guint       port);
-SOUP_AVAILABLE_IN_2_32
-const char *soup_uri_get_path              (SoupURI    *uri);
-SOUP_AVAILABLE_IN_2_4
-void        soup_uri_set_path              (SoupURI    *uri,
-                                           const char *path);
-SOUP_AVAILABLE_IN_2_32
-const char *soup_uri_get_query             (SoupURI    *uri);
+gboolean soup_uri_uses_default_port (GUri *uri);
+
 SOUP_AVAILABLE_IN_2_4
-void        soup_uri_set_query             (SoupURI    *uri,
-                                           const char *query);
+char      *soup_uri_normalize             (const char *part,
+                                           const char *unescape_extra);
 SOUP_AVAILABLE_IN_2_4
-void        soup_uri_set_query_from_form   (SoupURI    *uri,
+GUri       *soup_uri_copy_with_query_from_form (GUri       *uri,
                                            GHashTable *form);
+
 SOUP_AVAILABLE_IN_2_4
-void        soup_uri_set_query_from_fields (SoupURI    *uri,
+GUri       *soup_uri_copy_with_query_from_fields (GUri       *uri,
                                            const char *first_field,
                                            ...) G_GNUC_NULL_TERMINATED;
-SOUP_AVAILABLE_IN_2_32
-const char *soup_uri_get_fragment          (SoupURI    *uri);
-SOUP_AVAILABLE_IN_2_4
-void        soup_uri_set_fragment          (SoupURI    *uri,
-                                           const char *fragment);
-
 SOUP_AVAILABLE_IN_2_28
-SoupURI    *soup_uri_copy_host             (SoupURI    *uri);
+gboolean soup_uri_valid_for_http (GUri *uri, GError **error);
+
 SOUP_AVAILABLE_IN_2_28
-guint       soup_uri_host_hash             (gconstpointer key);
+GUri     *soup_uri_copy_with_credentials (GUri *uri, const char *username, const char *password);
+
 SOUP_AVAILABLE_IN_2_28
-gboolean    soup_uri_host_equal            (gconstpointer v1,
-                                           gconstpointer v2);
+gboolean  soup_uri_paths_equal (const char *path1, const char *path2, gssize len);
+
+#define SOUP_HTTP_URI_FLAGS (G_URI_FLAGS_HAS_PASSWORD | G_URI_FLAGS_ENCODED_PATH | G_URI_FLAGS_ENCODED_QUERY 
| G_URI_FLAGS_ENCODED_FRAGMENT)
 
-#define   SOUP_URI_IS_VALID(uri)       ((uri) && (uri)->scheme && (uri)->path)
-#define   SOUP_URI_VALID_FOR_HTTP(uri) ((uri) && ((uri)->scheme == SOUP_URI_SCHEME_HTTP || (uri)->scheme == 
SOUP_URI_SCHEME_HTTPS) && (uri)->host && (uri)->path)
+GUri *soup_normalize_uri (GUri *uri);
 
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(SoupURI, soup_uri_free)
+int   soup_uri_get_port_with_default (GUri *uri);
 
 G_END_DECLS
diff --git a/libsoup/websocket/soup-websocket-connection.c b/libsoup/websocket/soup-websocket-connection.c
index a6c34f40..d1b68014 100644
--- a/libsoup/websocket/soup-websocket-connection.c
+++ b/libsoup/websocket/soup-websocket-connection.c
@@ -116,7 +116,7 @@ typedef struct {
 typedef struct {
        GIOStream *io_stream;
        SoupWebsocketConnectionType connection_type;
-       SoupURI *uri;
+       GUri *uri;
        char *origin;
        char *protocol;
        guint64 max_incoming_payload_size;
@@ -1387,7 +1387,7 @@ soup_websocket_connection_set_property (GObject *object,
 
        case PROP_URI:
                g_return_if_fail (priv->uri == NULL);
-               priv->uri = g_value_dup_boxed (value);
+               priv->uri = soup_normalize_uri (g_value_get_boxed (value));
                break;
 
        case PROP_ORIGIN:
@@ -1458,7 +1458,7 @@ soup_websocket_connection_finalize (GObject *object)
                g_byte_array_free (priv->message_data, TRUE);
 
        if (priv->uri)
-               soup_uri_free (priv->uri);
+               g_uri_unref (priv->uri);
        g_free (priv->origin);
        g_free (priv->protocol);
 
@@ -1528,7 +1528,7 @@ soup_websocket_connection_class_init (SoupWebsocketConnectionClass *klass)
                                         g_param_spec_boxed ("uri",
                                                             "URI",
                                                             "The WebSocket URI",
-                                                            SOUP_TYPE_URI,
+                                                            G_TYPE_URI,
                                                             G_PARAM_READWRITE |
                                                             G_PARAM_CONSTRUCT_ONLY |
                                                             G_PARAM_STATIC_STRINGS));
@@ -1750,7 +1750,7 @@ soup_websocket_connection_class_init (SoupWebsocketConnectionClass *klass)
  */
 SoupWebsocketConnection *
 soup_websocket_connection_new (GIOStream                    *stream,
-                              SoupURI                      *uri,
+                              GUri                         *uri,
                               SoupWebsocketConnectionType   type,
                               const char                   *origin,
                               const char                   *protocol)
@@ -1777,7 +1777,7 @@ soup_websocket_connection_new (GIOStream                    *stream,
  */
 SoupWebsocketConnection *
 soup_websocket_connection_new_with_extensions (GIOStream                    *stream,
-                                               SoupURI                      *uri,
+                                               GUri                         *uri,
                                                SoupWebsocketConnectionType   type,
                                                const char                   *origin,
                                                const char                   *protocol,
@@ -1850,7 +1850,7 @@ soup_websocket_connection_get_connection_type (SoupWebsocketConnection *self)
  *
  * Since: 2.50
  */
-SoupURI *
+GUri *
 soup_websocket_connection_get_uri (SoupWebsocketConnection *self)
 {
         SoupWebsocketConnectionPrivate *priv = soup_websocket_connection_get_instance_private (self);
diff --git a/libsoup/websocket/soup-websocket-connection.h b/libsoup/websocket/soup-websocket-connection.h
index 503ba19c..ab013d0d 100644
--- a/libsoup/websocket/soup-websocket-connection.h
+++ b/libsoup/websocket/soup-websocket-connection.h
@@ -50,13 +50,13 @@ struct _SoupWebsocketConnectionClass {
 
 SOUP_AVAILABLE_IN_2_50
 SoupWebsocketConnection *soup_websocket_connection_new (GIOStream                    *stream,
-                                                       SoupURI                      *uri,
+                                                       GUri                         *uri,
                                                        SoupWebsocketConnectionType   type,
                                                        const char                   *origin,
                                                        const char                   *protocol);
 SOUP_AVAILABLE_IN_2_68
 SoupWebsocketConnection *soup_websocket_connection_new_with_extensions (GIOStream                    *stream,
-                                                                        SoupURI                      *uri,
+                                                                        GUri                         *uri,
                                                                         SoupWebsocketConnectionType   type,
                                                                         const char                   *origin,
                                                                         const char                   
*protocol,
@@ -69,7 +69,7 @@ SOUP_AVAILABLE_IN_2_50
 SoupWebsocketConnectionType soup_websocket_connection_get_connection_type (SoupWebsocketConnection *self);
 
 SOUP_AVAILABLE_IN_2_50
-SoupURI *           soup_websocket_connection_get_uri        (SoupWebsocketConnection *self);
+GUri *              soup_websocket_connection_get_uri        (SoupWebsocketConnection *self);
 
 SOUP_AVAILABLE_IN_2_50
 const char *        soup_websocket_connection_get_origin     (SoupWebsocketConnection *self);
diff --git a/meson.build b/meson.build
index 7cde64dc..5ae177dc 100644
--- a/meson.build
+++ b/meson.build
@@ -80,7 +80,7 @@ endif
 
 add_project_arguments(common_flags, language : 'c')
 
-glib_required_version = '>= 2.58'
+glib_required_version = '>= 2.65.2'
 glib_dep = dependency('glib-2.0', version : glib_required_version,
                        fallback: ['glib', 'libglib_dep'])
 gobject_dep = dependency('gobject-2.0', version : glib_required_version,
diff --git a/tests/auth-test.c b/tests/auth-test.c
index 9f7720ab..819301d4 100644
--- a/tests/auth-test.c
+++ b/tests/auth-test.c
@@ -789,7 +789,7 @@ select_auth_authenticate (SoupSession *session, SoupMessage *msg,
 }
 
 static void
-select_auth_test_one (SoupURI *uri,
+select_auth_test_one (GUri *uri,
                      gboolean disable_digest, const char *password,
                      const char *first_headers, const char *first_response,
                      const char *second_headers, const char *second_response,
@@ -873,7 +873,7 @@ do_select_auth_test (void)
 {
        SoupServer *server;
        SoupAuthDomain *basic_auth_domain, *digest_auth_domain;
-       SoupURI *uri;
+       GUri *uri;
 
        g_test_bug ("562339");
 
@@ -969,7 +969,7 @@ do_select_auth_test (void)
 
        g_object_unref (basic_auth_domain);
        g_object_unref (digest_auth_domain);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        soup_test_server_quit_unref (server);
 }
 
@@ -1026,7 +1026,7 @@ do_auth_close_test (void)
 {
        SoupServer *server;
        SoupAuthDomain *basic_auth_domain;
-       SoupURI *uri;
+       GUri *uri, *tmp;
        AuthCloseData acd;
        GBytes *body;
 
@@ -1035,7 +1035,9 @@ do_auth_close_test (void)
                                 server_callback, NULL, NULL);
 
        uri = soup_test_server_get_uri (server, "http", NULL);
-       soup_uri_set_path (uri, "/close");
+        tmp = g_uri_parse_relative (uri, "/close", SOUP_HTTP_URI_FLAGS, NULL);
+        g_uri_unref (uri);
+        uri = g_steal_pointer (&tmp);
 
        basic_auth_domain = soup_auth_domain_basic_new (
                SOUP_AUTH_DOMAIN_REALM, "auth-test",
@@ -1053,7 +1055,7 @@ do_auth_close_test (void)
                          G_CALLBACK (auth_close_authenticate), &acd);
 
        acd.msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        body = soup_test_session_async_send (acd.session, acd.msg);
 
        soup_test_assert_message_status (acd.msg, SOUP_STATUS_OK);
@@ -1137,7 +1139,7 @@ do_disappearing_auth_test (void)
 {
        SoupServer *server;
        SoupAuthDomain *auth_domain;
-       SoupURI *uri;
+       GUri *uri;
        SoupMessage *msg;
        SoupSession *session;
        int counter;
@@ -1178,7 +1180,7 @@ do_disappearing_auth_test (void)
        soup_test_session_abort_unref (session);
 
        g_object_unref (auth_domain);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        soup_test_server_quit_unref (server);
 }
 
@@ -1225,37 +1227,38 @@ do_batch_tests (gconstpointer data)
        SoupSession *session;
        SoupMessage *msg;
        char *expected, *uristr;
-       SoupURI *base;
+       GUri *base;
        guint signal;
        int i;
 
        SOUP_TEST_SKIP_IF_NO_APACHE;
 
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
-       base = soup_uri_new (base_uri);
+       base = g_uri_parse (base_uri, SOUP_HTTP_URI_FLAGS, NULL);
 
        for (i = 0; current_tests[i].url; i++) {
-               SoupURI *soup_uri = soup_uri_new_with_base (base, current_tests[i].url);
+               GUri *soup_uri = g_uri_parse_relative (base, current_tests[i].url, SOUP_HTTP_URI_FLAGS, NULL);
 
                debug_printf (1, "Test %d: %s\n", i + 1, current_tests[i].explanation);
 
                if (current_tests[i].url_auth) {
                        gchar *username = g_strdup_printf ("user%c", current_tests[i].provided[0]);
                        gchar *password = g_strdup_printf ("realm%c", current_tests[i].provided[0]);
-                       soup_uri_set_user (soup_uri, username);
-                       soup_uri_set_password (soup_uri, password);
+                        GUri *tmp = soup_uri_copy_with_credentials (soup_uri, username, password);
+                        g_uri_unref (soup_uri);
+                        soup_uri = tmp;
                        g_free (username);
                        g_free (password);
                }
 
                msg = soup_message_new_from_uri (SOUP_METHOD_GET, soup_uri);
-               soup_uri_free (soup_uri);
+               g_uri_unref (soup_uri);
                if (!msg) {
                        g_printerr ("auth-test: Could not parse URI\n");
                        exit (1);
                }
 
-               uristr = soup_uri_to_string (soup_message_get_uri (msg), FALSE);
+               uristr = g_uri_to_string (soup_message_get_uri (msg));
                debug_printf (1, "  GET %s\n", uristr);
                g_free (uristr);
 
@@ -1283,7 +1286,7 @@ do_batch_tests (gconstpointer data)
 
                g_object_unref (msg);
        }
-       soup_uri_free (base);
+       g_uri_unref (base);
 
        soup_test_session_abort_unref (session);
 }
@@ -1318,7 +1321,7 @@ do_message_do_not_use_auth_cache_test (void)
        SoupAuthManager *manager;
        SoupMessage *msg;
        SoupMessageFlags flags;
-       SoupURI *soup_uri;
+       GUri *soup_uri, *auth_uri;
        char *uri;
 
        SOUP_TEST_SKIP_IF_NO_APACHE;
@@ -1335,16 +1338,17 @@ do_message_do_not_use_auth_cache_test (void)
        /* Passing credentials in the URI should always authenticate
         * no matter whether the cache is used or not
         */
-       soup_uri = soup_uri_new (uri);
-       soup_uri_set_user (soup_uri, "user1");
-       soup_uri_set_password (soup_uri, "realm1");
-       msg = soup_message_new_from_uri (SOUP_METHOD_GET, soup_uri);
+       soup_uri = g_uri_parse (uri, SOUP_HTTP_URI_FLAGS, NULL);
+        auth_uri = soup_uri_copy_with_credentials (soup_uri, "user1", "realm1");
+
+       msg = soup_message_new_from_uri (SOUP_METHOD_GET, auth_uri);
        flags = soup_message_get_flags (msg);
        soup_message_set_flags (msg, flags | SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE);
        soup_test_session_send_message (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_object_unref (msg);
-       soup_uri_free (soup_uri);
+       g_uri_unref (soup_uri);
+        g_uri_unref (auth_uri);
 
        manager = SOUP_AUTH_MANAGER (soup_session_get_feature (session, SOUP_TYPE_AUTH_MANAGER));
 
diff --git a/tests/cache-test.c b/tests/cache-test.c
index 34e26be8..cfc76a72 100644
--- a/tests/cache-test.c
+++ b/tests/cache-test.c
@@ -111,7 +111,7 @@ is_network_stream (GInputStream *stream)
 }
 
 static char *do_request (SoupSession        *session,
-                        SoupURI            *base_uri,
+                        GUri               *base_uri,
                         const char         *method,
                         const char         *path,
                         SoupMessageHeaders *response_headers,
@@ -133,7 +133,7 @@ copy_headers (const char         *name,
 
 static char *
 do_request (SoupSession        *session,
-           SoupURI            *base_uri,
+           GUri               *base_uri,
            const char         *method,
            const char         *path,
            SoupMessageHeaders *response_headers,
@@ -142,7 +142,7 @@ do_request (SoupSession        *session,
        SoupRequestHTTP *req;
        SoupMessage *msg;
        GInputStream *stream;
-       SoupURI *uri;
+       GUri *uri;
        va_list ap;
        const char *header, *value;
        char buf[256];
@@ -152,9 +152,9 @@ do_request (SoupSession        *session,
        last_request_validated = last_request_hit_network = FALSE;
        last_request_unqueued = FALSE;
 
-       uri = soup_uri_new_with_base (base_uri, path);
+       uri = g_uri_parse_relative (base_uri, path, SOUP_HTTP_URI_FLAGS, NULL);
        req = soup_session_request_http_uri (session, method, uri, NULL);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        msg = soup_request_http_get_message (req);
 
        va_start (ap, response_headers);
@@ -213,23 +213,23 @@ do_request (SoupSession        *session,
 
 static void
 do_request_with_cancel (SoupSession          *session,
-                       SoupURI              *base_uri,
+                       GUri                 *base_uri,
                        const char           *method,
                        const char           *path,
                        SoupTestRequestFlags  flags)
 {
        SoupRequestHTTP *req;
        GInputStream *stream;
-       SoupURI *uri;
+       GUri *uri;
        GError *error = NULL;
        GCancellable *cancellable;
 
        last_request_validated = last_request_hit_network = last_request_unqueued = FALSE;
        cancelled_requests = 0;
 
-       uri = soup_uri_new_with_base (base_uri, path);
+       uri = g_uri_parse_relative (base_uri, path, SOUP_HTTP_URI_FLAGS, NULL);
        req = soup_session_request_http_uri (session, method, uri, NULL);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        cancellable = flags & SOUP_TEST_REQUEST_CANCEL_CANCELLABLE ? g_cancellable_new () : NULL;
        stream = soup_test_request_send (SOUP_REQUEST (req), cancellable, flags, &error);
        if (stream) {
@@ -255,7 +255,7 @@ message_starting (SoupMessage *msg, gpointer data)
            soup_message_headers_get_one (msg->request_headers,
                                          "If-None-Match")) {
                debug_printf (2, "    Conditional request for %s\n",
-                             soup_message_get_uri (msg)->path);
+                             g_uri_get_path (soup_message_get_uri (msg)));
                last_request_validated = TRUE;
        }
 }
@@ -281,7 +281,7 @@ request_unqueued (SoupSession *session, SoupMessage *msg,
 static void
 do_basics_test (gconstpointer data)
 {
-       SoupURI *base_uri = (SoupURI *)data;
+       GUri *base_uri = (GUri *)data;
        SoupSession *session;
        SoupCache *cache;
        char *cache_dir;
@@ -472,7 +472,7 @@ do_basics_test (gconstpointer data)
 static void
 do_cancel_test (gconstpointer data)
 {
-       SoupURI *base_uri = (SoupURI *)data;
+       GUri *base_uri = (GUri *)data;
        SoupSession *session;
        SoupCache *cache;
        char *cache_dir;
@@ -562,13 +562,13 @@ base_stream_unreffed (gpointer loop, GObject *ex_base_stream)
 static void
 do_refcounting_test (gconstpointer data)
 {
-       SoupURI *base_uri = (SoupURI *)data;
+       GUri *base_uri = (GUri *)data;
        SoupSession *session;
        SoupCache *cache;
        char *cache_dir;
        SoupRequestHTTP *req;
        GInputStream *stream, *base_stream;
-       SoupURI *uri;
+       GUri *uri;
        GError *error = NULL;
        guint flags;
        GMainLoop *loop;
@@ -585,9 +585,9 @@ do_refcounting_test (gconstpointer data)
        last_request_validated = last_request_hit_network = FALSE;
        cancelled_requests = 0;
 
-       uri = soup_uri_new_with_base (base_uri, "/1");
+       uri = g_uri_parse_relative (base_uri, "/1", SOUP_HTTP_URI_FLAGS, NULL);
        req = soup_session_request_http_uri (session, "GET", uri, NULL);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        flags = SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH | SOUP_TEST_REQUEST_CANCEL_MESSAGE;
        stream = soup_test_request_send (SOUP_REQUEST (req), NULL, flags, &error);
@@ -622,7 +622,7 @@ do_refcounting_test (gconstpointer data)
 static void
 do_headers_test (gconstpointer data)
 {
-       SoupURI *base_uri = (SoupURI *)data;
+       GUri *base_uri = (GUri *)data;
        SoupSession *session;
        SoupMessageHeaders *headers;
        SoupCache *cache;
@@ -701,7 +701,7 @@ count_cached_resources_in_dir (const char *cache_dir)
 static void
 do_leaks_test (gconstpointer data)
 {
-       SoupURI *base_uri = (SoupURI *)data;
+       GUri *base_uri = (GUri *)data;
        SoupSession *session;
        SoupCache *cache;
        char *cache_dir;
@@ -761,7 +761,7 @@ int
 main (int argc, char **argv)
 {
        SoupServer *server;
-       SoupURI *base_uri;
+       GUri *base_uri;
        int ret;
 
        test_init (argc, argv, NULL);
@@ -778,7 +778,7 @@ main (int argc, char **argv)
 
        ret = g_test_run ();
 
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
diff --git a/tests/chunk-io-test.c b/tests/chunk-io-test.c
index 8fd1928f..a655fd07 100644
--- a/tests/chunk-io-test.c
+++ b/tests/chunk-io-test.c
@@ -10,7 +10,7 @@ force_io_streams_init (void)
 {
        SoupServer *server;
        SoupSession *session;
-       SoupURI *base_uri;
+       GUri *base_uri;
        SoupMessage *msg;
 
        /* Poke libsoup enough to cause SoupBodyInputStream and
@@ -27,7 +27,7 @@ force_io_streams_init (void)
        g_object_unref (msg);
        soup_test_session_abort_unref (session);
 
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
        soup_test_server_quit_unref (server);
 }
 
diff --git a/tests/coding-test.c b/tests/coding-test.c
index 696f46f5..78be7076 100644
--- a/tests/coding-test.c
+++ b/tests/coding-test.c
@@ -6,8 +6,8 @@
 
 #include "test-utils.h"
 
-SoupServer *server;
-SoupURI *base_uri;
+static SoupServer *server;
+static GUri *base_uri;
 
 static void
 server_callback (SoupServer *server, SoupMessage *msg,
@@ -168,12 +168,12 @@ setup_coding_test (CodingTestData *data, gconstpointer test_data)
 {
        CodingTestType test_type = GPOINTER_TO_INT (test_data);
        SoupMessage *msg;
-       SoupURI *uri;
+       GUri *uri;
 
        data->session = soup_test_session_new (SOUP_TYPE_SESSION,
                                               NULL);
 
-       uri = soup_uri_new_with_base (base_uri, "/mbox");
+       uri = g_uri_parse_relative (base_uri, "/mbox", SOUP_HTTP_URI_FLAGS, NULL);
 
        if (test_type & CODING_TEST_EMPTY)
                data->response = g_bytes_new_static (NULL, 0);
@@ -191,7 +191,7 @@ setup_coding_test (CodingTestData *data, gconstpointer test_data)
                data->msg = soup_request_http_get_message (reqh);
        } else
                data->msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        if (test_type & CODING_TEST_NO_DECODER)
                soup_session_remove_feature_by_type (data->session, SOUP_TYPE_CONTENT_DECODER);
@@ -568,7 +568,7 @@ main (int argc, char **argv)
 
        ret = g_test_run ();
 
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
diff --git a/tests/connection-test.c b/tests/connection-test.c
index d267c3ec..ac098945 100644
--- a/tests/connection-test.c
+++ b/tests/connection-test.c
@@ -11,9 +11,9 @@
 
 #include <gio/gnetworking.h>
 
-SoupServer *server;
-SoupURI *base_uri;
-GMutex server_mutex;
+static SoupServer *server;
+static GUri *base_uri;
+static GMutex server_mutex;
 
 static void
 forget_close (SoupMessage *msg, gpointer user_data)
@@ -173,7 +173,7 @@ do_content_length_framing_test (void)
 {
        SoupSession *session;
        SoupMessage *msg;
-       SoupURI *request_uri;
+       GUri *request_uri;
        goffset declared_length;
        GBytes *body;
 
@@ -182,7 +182,7 @@ do_content_length_framing_test (void)
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
 
        debug_printf (1, "  Content-Length larger than message body length\n");
-       request_uri = soup_uri_new_with_base (base_uri, "/content-length/long");
+       request_uri = g_uri_parse_relative (base_uri, "/content-length/long", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", request_uri);
        body = soup_test_session_send (session, msg, NULL, NULL);
 
@@ -193,12 +193,12 @@ do_content_length_framing_test (void)
                      (gulong)declared_length, (char *)g_bytes_get_data (body, NULL));
        g_assert_cmpint (g_bytes_get_size (body), <, declared_length);
 
-       soup_uri_free (request_uri);
+       g_uri_unref (request_uri);
        g_bytes_unref (body);
        g_object_unref (msg);
 
        debug_printf (1, "  Server claims 'Connection: close' but doesn't\n");
-       request_uri = soup_uri_new_with_base (base_uri, "/content-length/noclose");
+       request_uri = g_uri_parse_relative (base_uri, "/content-length/noclose", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", request_uri);
        body = soup_test_session_send (session, msg, NULL, NULL);
 
@@ -207,7 +207,7 @@ do_content_length_framing_test (void)
        declared_length = soup_message_headers_get_content_length (msg->response_headers);
        g_assert_cmpint (g_bytes_get_size (body), ==, declared_length);
 
-       soup_uri_free (request_uri);
+       g_uri_unref (request_uri);
        g_bytes_unref (body);
        g_object_unref (msg);
 
@@ -244,7 +244,7 @@ do_timeout_test_for_session (SoupSession *session)
 {
        SoupMessage *msg;
        SoupSocket *sockets[4] = { NULL, NULL, NULL, NULL };
-       SoupURI *timeout_uri;
+       GUri *timeout_uri;
        int i;
        GBytes *body;
 
@@ -253,9 +253,9 @@ do_timeout_test_for_session (SoupSession *session)
                          &sockets);
 
        debug_printf (1, "    First message\n");
-       timeout_uri = soup_uri_new_with_base (base_uri, "/timeout-persistent");
+       timeout_uri = g_uri_parse_relative (base_uri, "/timeout-persistent", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", timeout_uri);
-       soup_uri_free (timeout_uri);
+       g_uri_unref (timeout_uri);
        body = soup_test_session_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
 
@@ -299,7 +299,7 @@ do_timeout_req_test_for_session (SoupSession *session)
        SoupMessage *msg;
        GInputStream *stream;
        SoupSocket *sockets[4] = { NULL, NULL, NULL, NULL };
-       SoupURI *timeout_uri;
+       GUri *timeout_uri;
        GError *error = NULL;
        int i;
 
@@ -308,9 +308,9 @@ do_timeout_req_test_for_session (SoupSession *session)
                          &sockets);
 
        debug_printf (1, "    First request\n");
-       timeout_uri = soup_uri_new_with_base (base_uri, "/timeout-persistent");
+       timeout_uri = g_uri_parse_relative (base_uri, "/timeout-persistent", SOUP_HTTP_URI_FLAGS, NULL);
        req = soup_session_request_uri (session, timeout_uri, NULL);
-       soup_uri_free (timeout_uri);
+       g_uri_unref (timeout_uri);
 
        stream = soup_test_request_send (req, NULL, 0, &error);
        if (error) {
@@ -408,7 +408,7 @@ do_persistent_connection_timeout_test_with_cancellation (void)
        SoupSession *session;
        SoupMessage *msg;
        SoupSocket *sockets[4] = { NULL, NULL, NULL, NULL };
-       SoupURI *timeout_uri;
+       GUri *timeout_uri;
        GCancellable *cancellable;
        GInputStream *response;
        int i;
@@ -421,10 +421,10 @@ do_persistent_connection_timeout_test_with_cancellation (void)
                          &sockets);
 
        debug_printf (1, "    First message\n");
-       timeout_uri = soup_uri_new_with_base (base_uri, "/timeout-persistent");
+       timeout_uri = g_uri_parse_relative (base_uri, "/timeout-persistent", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", timeout_uri);
        cancellable = g_cancellable_new ();
-       soup_uri_free (timeout_uri);
+       g_uri_unref (timeout_uri);
        response = soup_session_send (session, msg, cancellable, NULL);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
 
@@ -998,7 +998,7 @@ main (int argc, char **argv)
 
        ret = g_test_run ();
 
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
diff --git a/tests/context-test.c b/tests/context-test.c
index a47a3142..2def7c07 100644
--- a/tests/context-test.c
+++ b/tests/context-test.c
@@ -321,7 +321,7 @@ int
 main (int argc, char **argv)
 {
        SoupServer *server;
-       SoupURI *uri;
+       GUri *uri;
        int ret;
 
        test_init (argc, argv, NULL);
@@ -329,8 +329,8 @@ main (int argc, char **argv)
        server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
        soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
        uri = soup_test_server_get_uri (server, "http", NULL);
-       base_uri = soup_uri_to_string (uri, FALSE);
-       soup_uri_free (uri);
+       base_uri = g_uri_to_string (uri);
+       g_uri_unref (uri);
 
        g_test_add_func ("/context/blocking/thread-default", do_test1);
        g_test_add_func ("/context/nested/thread-default", do_test2);
diff --git a/tests/continue-test.c b/tests/continue-test.c
index 85d1a4e6..8a7579dd 100644
--- a/tests/continue-test.c
+++ b/tests/continue-test.c
@@ -10,7 +10,7 @@
 
 #define MAX_POST_LENGTH (sizeof (SHORT_BODY))
 
-static SoupURI *base_uri;
+static GUri *base_uri;
 static GSList *events;
 
 static void
@@ -61,7 +61,7 @@ do_message (const char *path, gboolean long_body,
        SoupSession *session;
        SoupMessage *msg;
        const char *body;
-       SoupURI *uri;
+       GUri *uri, *msg_uri;
        va_list ap;
        const char *expected_event;
        char *actual_event;
@@ -69,15 +69,15 @@ do_message (const char *path, gboolean long_body,
        GBytes *request_body;
        GBytes *response_body;
 
-       uri = soup_uri_copy (base_uri);
-       if (auth) {
-               soup_uri_set_user (uri, "user");
-               soup_uri_set_password (uri, "pass");
-       }
-       soup_uri_set_path (uri, path);
-       msg = soup_message_new_from_uri ("POST", uri);
-       g_print ("DBG: soup_message_new_from_uri: %p\n", msg);
-       soup_uri_free (uri);
+       if (auth)
+                uri = soup_uri_copy_with_credentials (base_uri, "user", "pass");
+        else
+                uri = g_uri_ref (base_uri);
+
+        msg_uri = g_uri_parse_relative (uri, path, SOUP_HTTP_URI_FLAGS, NULL);
+       msg = soup_message_new_from_uri ("POST", msg_uri);
+       g_uri_unref (uri);
+       g_uri_unref (msg_uri);
 
        body = long_body ? LONG_BODY : SHORT_BODY;
        request_body = g_bytes_new_static (body, strlen (body));
@@ -519,7 +519,7 @@ main (int argc, char **argv)
        ret = g_test_run ();
 
        soup_test_server_quit_unref (server);
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
 
        test_cleanup ();
 
diff --git a/tests/cookies-test.c b/tests/cookies-test.c
index 63c9e711..d1621567 100644
--- a/tests/cookies-test.c
+++ b/tests/cookies-test.c
@@ -5,10 +5,8 @@
 
 #include "test-utils.h"
 
-SoupServer *server;
-SoupURI *first_party_uri, *third_party_uri;
-const char *first_party = "http://127.0.0.1/";;
-const char *third_party = "http://localhost/";;
+static SoupServer *server;
+static GUri *first_party_uri, *third_party_uri;
 
 static void
 server_callback (SoupServer *server, SoupMessage *msg,
@@ -53,7 +51,7 @@ do_cookies_accept_policy_test (void)
 {
        SoupSession *session;
        SoupMessage *msg;
-       SoupURI *uri;
+       GUri *uri;
        SoupCookieJar *jar;
        GSList *l, *p;
        int i;
@@ -69,26 +67,26 @@ do_cookies_accept_policy_test (void)
                 * test_server, so let's swap first and third party here
                 * to simulate a cookie coming from a third party.
                 */
-               uri = soup_uri_new_with_base (first_party_uri, "/foo.jpg");
+               uri = g_uri_parse_relative (first_party_uri, "/foo.jpg", SOUP_HTTP_URI_FLAGS, NULL);
                msg = soup_message_new_from_uri ("GET", uri);
                soup_message_set_first_party (msg, third_party_uri);
                soup_test_session_send_message (session, msg);
-               soup_uri_free (uri);
+               g_uri_unref (uri);
                g_object_unref (msg);
 
-               uri = soup_uri_new_with_base (first_party_uri, "/index.html");
+               uri = g_uri_parse_relative (first_party_uri, "/index.html", SOUP_HTTP_URI_FLAGS, NULL);
                msg = soup_message_new_from_uri ("GET", uri);
                soup_message_set_first_party (msg, first_party_uri);
                soup_test_session_send_message (session, msg);
-               soup_uri_free (uri);
+               g_uri_unref (uri);
                g_object_unref (msg);
-
+        
                if (validResults[i].try_third_party_again) {
-                       uri = soup_uri_new_with_base (first_party_uri, "/foo.jpg");
-                       msg = soup_message_new_from_uri ("GET", uri);
+                        uri = g_uri_parse_relative (first_party_uri, "/foo.jpg", SOUP_HTTP_URI_FLAGS, NULL);
+                        msg = soup_message_new_from_uri ("GET", uri);
                        soup_message_set_first_party (msg, third_party_uri);
                        soup_test_session_send_message (session, msg);
-                       soup_uri_free (uri);
+                       g_uri_unref (uri);
                        g_object_unref (msg);
                }
 
@@ -111,18 +109,18 @@ do_cookies_subdomain_policy_test (void)
 {
        SoupCookieJar *jar;
        GSList *cookies;
-       SoupURI *uri1;
-       SoupURI *uri2;
-       SoupURI *uri3;
+       GUri *uri1;
+       GUri *uri2;
+       GUri *uri3;
 
        g_test_bug ("792130");
 
        /* Only the base domain should be considered when deciding
         * whether a cookie is a third-party cookie.
         */
-       uri1 = soup_uri_new ("https://www.gnome.org";);
-       uri2 = soup_uri_new ("https://foundation.gnome.org";);
-       uri3 = soup_uri_new ("https://www.gnome.org.";);
+       uri1 = g_uri_parse ("https://www.gnome.org";, SOUP_HTTP_URI_FLAGS, NULL);
+       uri2 = g_uri_parse ("https://foundation.gnome.org";, SOUP_HTTP_URI_FLAGS, NULL);
+       uri3 = g_uri_parse ("https://www.gnome.org.";, SOUP_HTTP_URI_FLAGS, NULL);
 
        /* We can't check subdomains with a test server running on
         * localhost, so we'll just check the cookie jar API itself.
@@ -232,9 +230,9 @@ do_cookies_subdomain_policy_test (void)
        g_assert_cmpint (g_slist_length (cookies), ==, 7);
        g_slist_free_full (cookies, (GDestroyNotify)soup_cookie_free);
 
-       soup_uri_free (uri1);
-       soup_uri_free (uri2);
-       soup_uri_free (uri3);
+       g_uri_unref (uri1);
+       g_uri_unref (uri2);
+       g_uri_unref (uri3);
        g_object_unref (jar);
 }
 
@@ -243,11 +241,11 @@ do_cookies_strict_secure_test (void)
 {
        SoupCookieJar *jar;
        GSList *cookies;
-       SoupURI *insecure_uri;
-       SoupURI *secure_uri;
+       GUri *insecure_uri;
+       GUri *secure_uri;
 
-       insecure_uri = soup_uri_new ("http://gnome.org";);
-       secure_uri = soup_uri_new ("https://gnome.org";);
+       insecure_uri = g_uri_parse ("http://gnome.org";, SOUP_HTTP_URI_FLAGS, NULL);
+       secure_uri = g_uri_parse ("https://gnome.org";, SOUP_HTTP_URI_FLAGS, NULL);
        jar = soup_cookie_jar_new ();
 
        /* Set a cookie from secure origin */
@@ -276,8 +274,8 @@ do_cookies_strict_secure_test (void)
        g_assert_cmpint (g_slist_length (cookies), ==, 2);
        g_slist_free_full (cookies, (GDestroyNotify)soup_cookie_free);
 
-       soup_uri_free (insecure_uri);
-       soup_uri_free (secure_uri);
+       g_uri_unref (insecure_uri);
+       g_uri_unref (secure_uri);
        g_object_unref (jar);
 }
 
@@ -366,18 +364,18 @@ static void
 do_get_cookies_empty_host_test (void)
 {
        SoupCookieJar *jar;
-       SoupURI *uri;
+       GUri *uri;
        char *cookies;
 
        jar = soup_cookie_jar_new ();
-       uri = soup_uri_new ("file:///whatever.html");
+       uri = g_uri_parse ("file:///whatever.html", SOUP_HTTP_URI_FLAGS, NULL);
 
        cookies = soup_cookie_jar_get_cookies (jar, uri, FALSE);
 
        g_assert_null (cookies);
 
        g_object_unref (jar);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 }
 
 static void
@@ -393,12 +391,12 @@ do_remove_feature_test (void)
 {
        SoupSession *session;
        SoupMessage *msg;
-       SoupURI *uri;
+       GUri *uri;
        GMainLoop *loop;
 
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
        soup_session_add_feature_by_type (session, SOUP_TYPE_COOKIE_JAR);
-       uri = soup_uri_new_with_base (first_party_uri, "/index.html");
+       uri = g_uri_parse_relative (first_party_uri, "/index.html", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
        soup_message_set_first_party (msg, first_party_uri);
 
@@ -410,13 +408,13 @@ do_remove_feature_test (void)
 
        g_main_loop_unref (loop);
        g_object_unref (msg);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 }
 
 int
 main (int argc, char **argv)
 {
-       SoupURI *server_uri;
+       GUri *server_uri;
        int ret;
 
        test_init (argc, argv, NULL);
@@ -425,10 +423,10 @@ main (int argc, char **argv)
        soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
        server_uri = soup_test_server_get_uri (server, "http", NULL);
 
-       first_party_uri = soup_uri_new (first_party);
-       third_party_uri = soup_uri_new (third_party);
-       soup_uri_set_port (first_party_uri, server_uri->port);
-       soup_uri_set_port (third_party_uri, server_uri->port);
+       first_party_uri = g_uri_build (SOUP_HTTP_URI_FLAGS, "http", NULL, "127.0.0.1",
+                                       g_uri_get_port (server_uri), "/", NULL, NULL);
+        third_party_uri = g_uri_build (SOUP_HTTP_URI_FLAGS, "http", NULL, "localhost",
+                                       g_uri_get_port (server_uri), "/", NULL, NULL);
 
        g_test_add_func ("/cookies/accept-policy", do_cookies_accept_policy_test);
        g_test_add_func ("/cookies/accept-policy-subdomains", do_cookies_subdomain_policy_test);
@@ -440,9 +438,9 @@ main (int argc, char **argv)
 
        ret = g_test_run ();
 
-       soup_uri_free (first_party_uri);
-       soup_uri_free (third_party_uri);
-       soup_uri_free (server_uri);
+       g_uri_unref (first_party_uri);
+       g_uri_unref (third_party_uri);
+       g_uri_unref (server_uri);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
diff --git a/tests/forms-test.c b/tests/forms-test.c
index 1a07fa00..3ae4ee46 100644
--- a/tests/forms-test.c
+++ b/tests/forms-test.c
@@ -357,7 +357,7 @@ md5_post_callback (SoupServer *server, SoupMessage *msg,
        const char *fmt;
        char *filename, *md5sum, *redirect_uri;
        GBytes *file;
-       SoupURI *uri;
+       GUri *uri;
 
        content_type = soup_message_headers_get_content_type (msg->request_headers, NULL);
        if (!content_type || strcmp (content_type, "multipart/form-data") != 0) {
@@ -376,18 +376,17 @@ md5_post_callback (SoupServer *server, SoupMessage *msg,
        md5sum = g_compute_checksum_for_bytes (G_CHECKSUM_MD5, file);
        g_bytes_unref (file);
 
-       uri = soup_uri_copy (soup_message_get_uri (msg));
-       soup_uri_set_query_from_fields (uri,
-                                       "file", filename ? filename : "",
-                                       "md5sum", md5sum,
-                                       "fmt", fmt ? fmt : "html",
-                                       NULL);
-       redirect_uri = soup_uri_to_string (uri, FALSE);
+       uri = soup_uri_copy_with_query_from_fields (soup_message_get_uri (msg),
+                                                   "file", filename ? filename : "",
+                                                   "md5sum", md5sum,
+                                                   "fmt", fmt ? fmt : "html",
+                                                   NULL);
+       redirect_uri = g_uri_to_string (uri);
 
        soup_message_set_redirect (msg, SOUP_STATUS_SEE_OTHER, redirect_uri);
 
        g_free (redirect_uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        g_free (md5sum);
        g_free (filename);
        g_hash_table_destroy (params);
@@ -420,7 +419,7 @@ main (int argc, char **argv)
 {
        GMainLoop *loop;
        SoupServer *server;
-       SoupURI *base_uri, *uri;
+       GUri *base_uri, *uri;
        int ret = 0;
 
        test_init (argc, argv, no_test_entry);
@@ -435,27 +434,27 @@ main (int argc, char **argv)
        loop = g_main_loop_new (NULL, TRUE);
 
        if (run_tests) {
-               uri = soup_uri_new_with_base (base_uri, "/hello");
-               g_test_add_data_func_full ("/forms/hello", soup_uri_to_string (uri, FALSE), do_hello_tests, 
g_free);
-               soup_uri_free (uri);
+               uri = g_uri_parse_relative (base_uri, "/hello", SOUP_HTTP_URI_FLAGS, NULL);
+               g_test_add_data_func_full ("/forms/hello", g_uri_to_string (uri), do_hello_tests, g_free);
+               g_uri_unref (uri);
 
-               uri = soup_uri_new_with_base (base_uri, "/md5");
-               g_test_add_data_func_full ("/forms/md5/curl", soup_uri_to_string (uri, FALSE), 
do_md5_test_curl, g_free);
-               g_test_add_data_func_full ("/forms/md5/libsoup", soup_uri_to_string (uri, FALSE), 
do_md5_test_libsoup, g_free);
-               soup_uri_free (uri);
+               uri = g_uri_parse_relative (base_uri, "/md5", SOUP_HTTP_URI_FLAGS, NULL);
+               g_test_add_data_func_full ("/forms/md5/curl", g_uri_to_string (uri), do_md5_test_curl, 
g_free);
+               g_test_add_data_func_full ("/forms/md5/libsoup", g_uri_to_string (uri), do_md5_test_libsoup, 
g_free);
+               g_uri_unref (uri);
 
                g_test_add_func ("/forms/decode", do_form_decode_test);
 
                ret = g_test_run ();
        } else {
-               g_print ("Listening on port %d\n", base_uri->port);
+               g_print ("Listening on port %d\n", g_uri_get_port (base_uri));
                g_main_loop_run (loop);
        }
 
        g_main_loop_unref (loop);
 
        soup_test_server_quit_unref (server);
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
 
        if (run_tests)
                test_cleanup ();
diff --git a/tests/hsts-db-test.c b/tests/hsts-db-test.c
index f45e355d..b381c12e 100644
--- a/tests/hsts-db-test.c
+++ b/tests/hsts-db-test.c
@@ -6,8 +6,8 @@
 
 #define DB_FILE "hsts-db.sqlite"
 
-SoupURI *http_uri;
-SoupURI *https_uri;
+GUri *http_uri;
+GUri *https_uri;
 
 /* This server pseudo-implements the HSTS spec in order to allow us to
    test the Soup HSTS feature.
@@ -20,13 +20,11 @@ server_callback  (SoupServer *server, SoupMessage *msg,
        const char *server_protocol = data;
 
        if (strcmp (server_protocol, "http") == 0) {
-               char *uri_string;
-               SoupURI *uri = soup_uri_new ("https://localhost";);
-               soup_uri_set_path (uri, path);
-               uri_string = soup_uri_to_string (uri, FALSE);
+                GUri *uri = g_uri_build (SOUP_HTTP_URI_FLAGS, "https", NULL, "localhost", -1, path, NULL, 
NULL);
+               char *uri_string = g_uri_to_string (uri);
                fprintf (stderr, "server is redirecting to HTTPS\n");
                soup_message_set_redirect (msg, SOUP_STATUS_MOVED_PERMANENTLY, uri_string);
-               soup_uri_free (uri);
+               g_uri_unref (uri);
                g_free (uri_string);
        } else if (strcmp (server_protocol, "https") == 0) {
                soup_message_set_status (msg, SOUP_STATUS_OK);
@@ -77,12 +75,15 @@ session_get_uri (SoupSession *session, const char *uri, SoupStatus expected_stat
 static void
 rewrite_message_uri (SoupMessage *msg)
 {
-       if (soup_uri_get_scheme (soup_message_get_uri (msg)) == SOUP_URI_SCHEME_HTTP)
-               soup_uri_set_port (soup_message_get_uri (msg), soup_uri_get_port (http_uri));
-       else if (soup_uri_get_scheme (soup_message_get_uri (msg)) == SOUP_URI_SCHEME_HTTPS)
-               soup_uri_set_port (soup_message_get_uri (msg), soup_uri_get_port (https_uri));
+       GUri *new_uri;
+       if (soup_uri_is_http (soup_message_get_uri (msg), NULL))
+               new_uri = soup_test_uri_set_port (soup_message_get_uri (msg), g_uri_get_port (http_uri));
+       else if (soup_uri_is_https (soup_message_get_uri (msg), NULL))
+               new_uri = soup_test_uri_set_port (soup_message_get_uri (msg), g_uri_get_port (https_uri));
        else
                g_assert_not_reached();
+       soup_message_set_uri (msg, new_uri);
+       g_uri_unref (new_uri);
 }
 
 static void
@@ -186,11 +187,11 @@ main (int argc, char **argv)
 
        ret = g_test_run ();
 
-       soup_uri_free (http_uri);
+       g_uri_unref (http_uri);
        soup_test_server_quit_unref (server);
 
        if (tls_available) {
-               soup_uri_free (https_uri);
+               g_uri_unref (https_uri);
                soup_test_server_quit_unref (https_server);
        }
 
diff --git a/tests/hsts-test.c b/tests/hsts-test.c
index e8c7d877..1cfa1fdc 100644
--- a/tests/hsts-test.c
+++ b/tests/hsts-test.c
@@ -6,8 +6,8 @@
 
 #include "test-utils.h"
 
-SoupURI *http_uri;
-SoupURI *https_uri;
+GUri *http_uri;
+GUri *https_uri;
 
 /* This server pseudo-implements the HSTS spec in order to allow us to
    test the Soup HSTS feature.
@@ -26,12 +26,10 @@ server_callback  (SoupServer *server, SoupMessage *msg,
                                                     "max-age=31536000");
                        soup_message_set_status (msg, SOUP_STATUS_OK);
                } else {
-                       char *uri_string;
-                       SoupURI *uri = soup_uri_new ("https://localhost";);
-                       soup_uri_set_path (uri, path);
-                       uri_string = soup_uri_to_string (uri, FALSE);
+                        GUri *uri = g_uri_build (SOUP_HTTP_URI_FLAGS, "https", NULL, "localhost", -1, path, 
NULL, NULL);
+                       char *uri_string = g_uri_to_string (uri);
                        soup_message_set_redirect (msg, SOUP_STATUS_MOVED_PERMANENTLY, uri_string);
-                       soup_uri_free (uri);
+                       g_uri_unref (uri);
                        g_free (uri_string);
                }
        } else if (strcmp (server_protocol, "https") == 0) {
@@ -123,12 +121,15 @@ session_get_uri (SoupSession *session, const char *uri, SoupStatus expected_stat
 static void
 rewrite_message_uri (SoupMessage *msg)
 {
-       if (soup_uri_get_scheme (soup_message_get_uri (msg)) == SOUP_URI_SCHEME_HTTP)
-               soup_uri_set_port (soup_message_get_uri (msg), soup_uri_get_port (http_uri));
-       else if (soup_uri_get_scheme (soup_message_get_uri (msg)) == SOUP_URI_SCHEME_HTTPS)
-               soup_uri_set_port (soup_message_get_uri (msg), soup_uri_get_port (https_uri));
+       GUri *new_uri;
+       if (soup_uri_is_http (soup_message_get_uri (msg), NULL))
+               new_uri = soup_test_uri_set_port (soup_message_get_uri (msg), g_uri_get_port (http_uri));
+       else if (soup_uri_is_https (soup_message_get_uri (msg), NULL))
+               new_uri = soup_test_uri_set_port (soup_message_get_uri (msg), g_uri_get_port (https_uri));
        else
                g_assert_not_reached();
+       soup_message_set_uri (msg, new_uri);
+       g_uri_unref (new_uri);
 }
 
 static void
@@ -603,11 +604,11 @@ main (int argc, char **argv)
 
        ret = g_test_run ();
 
-       soup_uri_free (http_uri);
+       g_uri_unref (http_uri);
        soup_test_server_quit_unref (server);
 
        if (tls_available) {
-               soup_uri_free (https_uri);
+               g_uri_unref (https_uri);
                soup_test_server_quit_unref (https_server);
        }
 
diff --git a/tests/misc-test.c b/tests/misc-test.c
index 759c2abf..3ea7d9c7 100644
--- a/tests/misc-test.c
+++ b/tests/misc-test.c
@@ -8,7 +8,7 @@
 #include "soup-session-private.h"
 
 SoupServer *server, *ssl_server;
-SoupURI *base_uri, *ssl_base_uri;
+GUri *base_uri, *ssl_base_uri;
 
 static gboolean
 auth_callback (SoupAuthDomain *auth_domain, SoupMessage *msg,
@@ -31,7 +31,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
                 const char *path, GHashTable *query,
                 SoupClientContext *context, gpointer data)
 {
-       SoupURI *uri = soup_message_get_uri (msg);
+       GUri *uri = soup_message_get_uri (msg);
        const char *server_protocol = data;
 
        if (msg->method != SOUP_METHOD_GET && msg->method != SOUP_METHOD_POST) {
@@ -45,24 +45,24 @@ server_callback (SoupServer *server, SoupMessage *msg,
        }
 
        if (!strcmp (path, "/alias-redirect")) {
-               SoupURI *redirect_uri;
+               GUri *redirect_uri;
                char *redirect_string;
                const char *redirect_protocol;
+                int redirect_port;
 
                redirect_protocol = soup_message_headers_get_one (msg->request_headers, 
"X-Redirect-Protocol");
-
-               redirect_uri = soup_uri_copy (uri);
-               soup_uri_set_scheme (redirect_uri, "foo");
                if (!g_strcmp0 (redirect_protocol, "https"))
-                       soup_uri_set_port (redirect_uri, ssl_base_uri->port);
+                        redirect_port = g_uri_get_port (ssl_base_uri);
                else
-                       soup_uri_set_port (redirect_uri, base_uri->port);
-               soup_uri_set_path (redirect_uri, "/alias-redirected");
-               redirect_string = soup_uri_to_string (redirect_uri, FALSE);
+                        redirect_port = g_uri_get_port (base_uri);
+
+                redirect_uri = g_uri_build (SOUP_HTTP_URI_FLAGS, "foo", NULL, g_uri_get_host (uri), 
redirect_port,
+                                            "/alias-redirected", NULL, NULL);
+               redirect_string = g_uri_to_string (redirect_uri);
 
                soup_message_set_redirect (msg, SOUP_STATUS_FOUND, redirect_string);
                g_free (redirect_string);
-               soup_uri_free (redirect_uri);
+               g_uri_unref (redirect_uri);
                return;
        } else if (!strcmp (path, "/alias-redirected")) {
                soup_message_set_status (msg, SOUP_STATUS_OK);
@@ -80,7 +80,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
        }
 
        soup_message_set_status (msg, SOUP_STATUS_OK);
-       if (!strcmp (uri->host, "foo")) {
+       if (!strcmp (g_uri_get_host (uri), "foo")) {
                soup_message_set_response (msg, "text/plain",
                                           SOUP_MEMORY_STATIC, "foo-index", 9);
                return;
@@ -195,7 +195,7 @@ do_callback_unref_test (void)
        SoupSession *session;
        SoupMessage *one, *two;
        GMainLoop *loop;
-       SoupURI *bad_uri;
+       GUri *bad_uri;
 
        g_test_bug ("533473");
 
@@ -217,7 +217,7 @@ do_callback_unref_test (void)
        g_signal_connect (two, "finished",
                          G_CALLBACK (cu_two_completed), loop);
        g_object_add_weak_pointer (G_OBJECT (two), (gpointer *)&two);
-       soup_uri_free (bad_uri);
+       g_uri_unref (bad_uri);
 
        soup_session_send_async (session, one, NULL, NULL, NULL);
        soup_session_send_async (session, two, NULL, NULL, NULL);
@@ -288,7 +288,7 @@ do_callback_unref_req_test (void)
        SoupSession *session;
        SoupRequest *one, *two;
        GMainLoop *loop;
-       SoupURI *bad_uri;
+       GUri *bad_uri;
 
        /* Get a guaranteed-bad URI */
        bad_server = soup_test_server_new (SOUP_TEST_SERVER_DEFAULT);
@@ -305,7 +305,7 @@ do_callback_unref_req_test (void)
        g_object_add_weak_pointer (G_OBJECT (one), (gpointer *)&one);
        two = soup_session_request_uri (session, bad_uri, NULL);
        g_object_add_weak_pointer (G_OBJECT (two), (gpointer *)&two);
-       soup_uri_free (bad_uri);
+       g_uri_unref (bad_uri);
 
        soup_request_send_async (one, NULL, cur_one_completed, session);
        g_object_unref (one);
@@ -368,7 +368,7 @@ do_msg_reuse_test (void)
 {
        SoupSession *session;
        SoupMessage *msg;
-       SoupURI *uri;
+       GUri *uri;
        guint *signal_ids, n_signal_ids;
 
        g_test_bug ("559054");
@@ -385,23 +385,19 @@ do_msg_reuse_test (void)
        ensure_no_signal_handlers (msg, signal_ids, n_signal_ids);
 
        debug_printf (1, "  Redirect message\n");
-       uri = soup_uri_new_with_base (base_uri, "/redirect");
+       uri = g_uri_parse_relative (base_uri, "/redirect", SOUP_HTTP_URI_FLAGS, NULL);
        soup_message_set_uri (msg, uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        soup_test_session_async_send (session, msg);
        g_assert_true (soup_uri_equal (soup_message_get_uri (msg), base_uri));
        ensure_no_signal_handlers (msg, signal_ids, n_signal_ids);
 
        debug_printf (1, "  Auth message\n");
-       uri = soup_uri_new_with_base (base_uri, "/auth");
+       uri = g_uri_parse_relative (base_uri, "/auth", SOUP_HTTP_URI_FLAGS, NULL);
        soup_message_set_uri (msg, uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        soup_test_session_async_send (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
-       ensure_no_signal_handlers (msg, signal_ids, n_signal_ids);
-
-       /* One last try to make sure the auth stuff got cleaned up */
-       debug_printf (1, "  Last message\n");
        soup_message_set_uri (msg, base_uri);
        soup_test_session_async_send (session, msg);
        ensure_no_signal_handlers (msg, signal_ids, n_signal_ids);
@@ -696,12 +692,12 @@ static void
 do_cancel_while_reading_test_for_session (SoupSession *session)
 {
        SoupMessage *msg;
-       SoupURI *uri;
+       GUri *uri;
        gboolean done = FALSE;
 
-       uri = soup_uri_new_with_base (base_uri, "/slow");
+       uri = g_uri_parse_relative (base_uri, "/slow", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        g_object_set_data (G_OBJECT (msg), "session", session);
        g_object_ref (msg);
@@ -740,13 +736,13 @@ do_cancel_while_reading_req_test_for_session (SoupSession *session,
                                              guint flags)
 {
        SoupRequest *req;
-       SoupURI *uri;
+       GUri *uri;
        GCancellable *cancellable;
        GError *error = NULL;
 
-       uri = soup_uri_new_with_base (base_uri, "/slow");
+       uri = g_uri_parse_relative (base_uri, "/slow", SOUP_HTTP_URI_FLAGS, NULL);
        req = soup_session_request_uri (session, uri, NULL);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        cancellable = g_cancellable_new ();
        soup_test_request_send (req, cancellable, flags, &error);
@@ -808,14 +804,14 @@ do_aliases_test_for_session (SoupSession *session,
                             const char *redirect_protocol)
 {
        SoupMessage *msg;
-       SoupURI *uri;
+       GUri *uri;
        const char *redirected_protocol;
 
-       uri = soup_uri_new_with_base (base_uri, "/alias-redirect");
+       uri = g_uri_parse_relative (base_uri, "/alias-redirect", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
        if (redirect_protocol)
                soup_message_headers_append (msg->request_headers, "X-Redirect-Protocol", redirect_protocol);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        soup_test_session_send_message (session, msg);
 
        redirected_protocol = soup_message_headers_get_one (msg->response_headers, "X-Redirected-Protocol");
@@ -998,11 +994,11 @@ main (int argc, char **argv)
 
        ret = g_test_run ();
 
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
        soup_test_server_quit_unref (server);
 
        if (tls_available) {
-               soup_uri_free (ssl_base_uri);
+               g_uri_unref (ssl_base_uri);
                soup_test_server_quit_unref (ssl_server);
        }
 
diff --git a/tests/multipart-test.c b/tests/multipart-test.c
index c0c09dc8..22556625 100644
--- a/tests/multipart-test.c
+++ b/tests/multipart-test.c
@@ -25,7 +25,7 @@ typedef enum {
 char *buffer;
 SoupSession *session;
 char *base_uri_string;
-SoupURI *base_uri;
+GUri *base_uri;
 SoupMultipartInputStream *multipart;
 unsigned passes;
 
@@ -492,7 +492,7 @@ main (int argc, char **argv)
        server = soup_test_server_new (SOUP_TEST_SERVER_DEFAULT);
        soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
        base_uri = soup_test_server_get_uri (server, "http", NULL);
-       base_uri_string = soup_uri_to_string (base_uri, FALSE);
+       base_uri_string = g_uri_to_string (base_uri);
 
        /* FIXME: I had to raise the number of connections allowed here, otherwise I
         * was hitting the limit, which indicates some connections are not dying.
@@ -510,7 +510,7 @@ main (int argc, char **argv)
 
        ret = g_test_run ();
 
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
        g_free (base_uri_string);
        g_free (buffer);
 
diff --git a/tests/no-ssl-test.c b/tests/no-ssl-test.c
index b92dd2c2..ef61e5e1 100644
--- a/tests/no-ssl-test.c
+++ b/tests/no-ssl-test.c
@@ -3,7 +3,7 @@
 #include "test-utils.h"
 
 static void
-do_ssl_test_for_session (SoupSession *session, SoupURI *uri)
+do_ssl_test_for_session (SoupSession *session, GUri *uri)
 {
        SoupMessage *msg;
        GTlsCertificate *cert = NULL;
@@ -26,7 +26,7 @@ do_ssl_test_for_session (SoupSession *session, SoupURI *uri)
 static void
 do_ssl_tests (gconstpointer data)
 {
-       SoupURI *uri = (SoupURI *)data;
+       GUri *uri = (GUri *)data;
        SoupSession *session;
 
        g_test_bug ("700518");
@@ -50,12 +50,30 @@ server_handler (SoupServer        *server,
                                   "ok\r\n", 4);
 }
 
+static GUri *
+uri_set_scheme (GUri *uri, const char *scheme)
+{
+        GUri *new_uri = g_uri_build_with_user (
+                g_uri_get_flags (uri),
+                scheme,
+                g_uri_get_user (uri),
+                g_uri_get_password (uri),
+                g_uri_get_auth_params (uri),
+                g_uri_get_host (uri),
+                g_uri_get_port (uri),
+                g_uri_get_path (uri),
+                g_uri_get_query (uri),
+                g_uri_get_fragment (uri)
+        );
+        g_uri_unref (uri);
+        return new_uri;
+}
+
 int
 main (int argc, char **argv)
 {
        SoupServer *server;
-       SoupURI *uri;
-       guint port;
+       GUri *uri;
        int ret;
 
        /* Force this test to use the dummy TLS backend */
@@ -70,15 +88,13 @@ main (int argc, char **argv)
        server = soup_test_server_new (TRUE);
        soup_server_add_handler (server, NULL, server_handler, NULL, NULL);
        uri = soup_test_server_get_uri (server, "http", NULL);
-       port = uri->port;
-       soup_uri_set_scheme (uri, SOUP_URI_SCHEME_HTTPS);
-       soup_uri_set_port (uri, port);
+        uri = uri_set_scheme (uri, "https");
 
        g_test_add_data_func ("/no-ssl/request-error", uri, do_ssl_tests);
 
        ret = g_test_run ();
 
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
diff --git a/tests/ntlm-test.c b/tests/ntlm-test.c
index 0a980f9b..fb6a71c9 100644
--- a/tests/ntlm-test.c
+++ b/tests/ntlm-test.c
@@ -43,7 +43,7 @@ static const char *state_name[] = {
 typedef struct {
        SoupServer *server;
        GHashTable *connections;
-       SoupURI *uri;
+       GUri *uri;
        gboolean ntlmssp;
        gboolean ntlmv2;
 } TestServer;
@@ -194,7 +194,7 @@ static void
 teardown_server (TestServer *ts,
                 gconstpointer test_data)
 {
-       soup_uri_free (ts->uri);
+       g_uri_unref (ts->uri);
        soup_test_server_quit_unref (ts->server);
        g_hash_table_destroy (ts->connections);
 }
@@ -305,19 +305,19 @@ response_check (SoupMessage *msg, gpointer user_data)
 }
 
 static void
-do_message (SoupSession *session, SoupURI *base_uri, const char *path,
+do_message (SoupSession *session, GUri *base_uri, const char *path,
            gboolean get_ntlm_prompt, gboolean do_ntlm,
            gboolean get_basic_prompt, gboolean do_basic,
            guint status_code)
 {
-       SoupURI *uri;
+       GUri *uri;
        SoupMessage *msg;
        GBytes *body;
        NTLMState state = { FALSE, FALSE, FALSE, FALSE };
 
-       uri = soup_uri_new_with_base (base_uri, path);
+       uri = g_uri_parse_relative (base_uri, path, SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        g_signal_connect (msg, "got_headers",
                          G_CALLBACK (prompt_check), &state);
@@ -391,7 +391,7 @@ do_message (SoupSession *session, SoupURI *base_uri, const char *path,
 }
 
 static void
-do_ntlm_round (SoupURI *base_uri, gboolean use_ntlm,
+do_ntlm_round (GUri *base_uri, gboolean use_ntlm,
               const char *user, gboolean use_builtin_ntlm)
 {
        SoupSession *session;
@@ -636,7 +636,7 @@ do_retrying_test (TestServer *ts,
 {
        SoupSession *session;
        SoupMessage *msg;
-       SoupURI *uri;
+       GUri *uri;
        GBytes *body;
        gboolean retried = FALSE;
 
@@ -652,9 +652,9 @@ do_retrying_test (TestServer *ts,
        g_signal_connect (session, "authenticate",
                          G_CALLBACK (retry_test_authenticate), &retried);
 
-       uri = soup_uri_new_with_base (ts->uri, "/alice");
+       uri = g_uri_parse_relative (ts->uri, "/alice", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        body = soup_test_session_send (session, msg, NULL, NULL);
 
@@ -675,9 +675,9 @@ do_retrying_test (TestServer *ts,
                          G_CALLBACK (retry_test_authenticate), &retried);
        retried = FALSE;
 
-       uri = soup_uri_new_with_base (ts->uri, "/bob");
+       uri = g_uri_parse_relative (ts->uri, "/bob", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        body = soup_test_session_send (session, msg, NULL, NULL);
 
diff --git a/tests/proxy-test.c b/tests/proxy-test.c
index a17671d4..3fefb76f 100644
--- a/tests/proxy-test.c
+++ b/tests/proxy-test.c
@@ -189,18 +189,21 @@ do_proxy_test (SoupProxyTest *test)
                g_test_bug (test->bugref);
 
        if (!strncmp (test->url, "http", 4)) {
-               SoupURI *uri;
-               guint port;
+               GUri *http_uri, *https_uri;
+               int port;
 
                http_url = g_strdup (test->url);
 
-               uri = soup_uri_new (test->url);
-               port = uri->port;
-               soup_uri_set_scheme (uri, "https");
-               if (port)
-                       soup_uri_set_port (uri, port + 1);
-               https_url = soup_uri_to_string (uri, FALSE);
-               soup_uri_free (uri);
+                http_uri = g_uri_parse (test->url, SOUP_HTTP_URI_FLAGS, NULL);
+                port = g_uri_get_port (http_uri);
+                if (port != -1)
+                        port += 1;
+                https_uri = g_uri_build (SOUP_HTTP_URI_FLAGS, "https", NULL, g_uri_get_host (http_uri),
+                                         port, g_uri_get_path (http_uri),
+                                         g_uri_get_query (http_uri), g_uri_get_fragment (http_uri));
+               https_url = g_uri_to_string (https_uri);
+               g_uri_unref (http_uri);
+                g_uri_unref (https_uri);
        } else {
                http_url = g_strconcat (HTTP_SERVER, test->url, NULL);
                https_url = g_strconcat (HTTPS_SERVER, test->url, NULL);
@@ -242,17 +245,17 @@ server_callback (SoupServer *server, SoupMessage *msg,
                 const char *path, GHashTable *query,
                 SoupClientContext *context, gpointer data)
 {
-       SoupURI *uri = soup_message_get_uri (msg);
+       GUri *uri = soup_message_get_uri (msg);
 
-       soup_message_set_status (msg, uri->fragment ? SOUP_STATUS_BAD_REQUEST : SOUP_STATUS_OK);
+       soup_message_set_status (msg, g_uri_get_fragment (uri) ? SOUP_STATUS_BAD_REQUEST : SOUP_STATUS_OK);
 }
 
 static void
 do_proxy_fragment_test (gconstpointer data)
 {
-       SoupURI *base_uri = (SoupURI *)data;
+       GUri *base_uri = (GUri *)data;
        SoupSession *session;
-       SoupURI *req_uri;
+       GUri *req_uri;
        SoupMessage *msg;
 
        SOUP_TEST_SKIP_IF_NO_APACHE;
@@ -261,9 +264,9 @@ do_proxy_fragment_test (gconstpointer data)
                                         SOUP_SESSION_PROXY_RESOLVER, proxy_resolvers[SIMPLE_PROXY],
                                         NULL);
 
-       req_uri = soup_uri_new_with_base (base_uri, "/#foo");
+       req_uri = g_uri_parse_relative (base_uri, "/#foo", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri (SOUP_METHOD_GET, req_uri);
-       soup_uri_free (req_uri);
+       g_uri_unref (req_uri);
        soup_test_session_send_message (session, msg);
 
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
@@ -276,7 +279,7 @@ static void
 do_proxy_redirect_test (void)
 {
        SoupSession *session;
-       SoupURI *req_uri, *new_uri;
+       GUri *base_uri, *req_uri, *new_uri;
        SoupMessage *msg;
 
        g_test_bug ("631368");
@@ -288,17 +291,18 @@ do_proxy_redirect_test (void)
                                         SOUP_SESSION_PROXY_RESOLVER, proxy_resolvers[SIMPLE_PROXY],
                                         NULL);
 
-       req_uri = soup_uri_new (HTTPS_SERVER);
-       soup_uri_set_path (req_uri, "/redirected");
+       base_uri = g_uri_parse (HTTPS_SERVER, SOUP_HTTP_URI_FLAGS, NULL);
+        req_uri = g_uri_parse_relative (base_uri, "/redirected", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri (SOUP_METHOD_GET, req_uri);
        soup_message_headers_append (msg->request_headers,
                                     "Connection", "close");
        soup_test_session_send_message (session, msg);
 
        new_uri = soup_message_get_uri (msg);
-       soup_test_assert (strcmp (req_uri->path, new_uri->path) != 0,
+       soup_test_assert (strcmp (g_uri_get_path (req_uri), g_uri_get_path (new_uri)) != 0,
                          "message was not redirected");
-       soup_uri_free (req_uri);
+       g_uri_unref (req_uri);
+        g_uri_unref (base_uri);
 
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
 
@@ -387,7 +391,7 @@ int
 main (int argc, char **argv)
 {
        SoupServer *server;
-       SoupURI *base_uri;
+       GUri *base_uri;
        char *path;
        int i, ret;
 
@@ -415,7 +419,7 @@ main (int argc, char **argv)
 
        ret = g_test_run ();
 
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
        soup_test_server_quit_unref (server);
        for (i = 0; i < 3; i++)
                g_object_unref (proxy_resolvers[i]);
diff --git a/tests/range-test.c b/tests/range-test.c
index ce8a744b..19b2e0c5 100644
--- a/tests/range-test.c
+++ b/tests/range-test.c
@@ -365,7 +365,7 @@ do_libsoup_range_test (void)
 {
        SoupSession *session;
        SoupServer *server;
-       SoupURI *base_uri;
+       GUri *base_uri;
        char *base_uri_str;
 
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
@@ -373,9 +373,9 @@ do_libsoup_range_test (void)
        server = soup_test_server_new (SOUP_TEST_SERVER_DEFAULT);
        soup_server_add_handler (server, NULL, server_handler, NULL, NULL);
        base_uri = soup_test_server_get_uri (server, "http", NULL);
-       base_uri_str = soup_uri_to_string (base_uri, FALSE);
+       base_uri_str = g_uri_to_string (base_uri);
        do_range_test (session, base_uri_str, TRUE, TRUE);
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
        g_free (base_uri_str);
        soup_test_server_quit_unref (server);
 
diff --git a/tests/redirect-test.c b/tests/redirect-test.c
index d360065a..153a62d7 100644
--- a/tests/redirect-test.c
+++ b/tests/redirect-test.c
@@ -5,7 +5,7 @@
 
 #include "test-utils.h"
 
-SoupURI *base_uri;
+GUri *base_uri;
 char *server2_uri;
 SoupSession *async_session;
 
@@ -143,9 +143,9 @@ static void
 restarted (SoupMessage *msg, gpointer user_data)
 {
        TestRequest **treq = user_data;
-       SoupURI *uri = soup_message_get_uri (msg);
+       GUri *uri = soup_message_get_uri (msg);
 
-       debug_printf (2, "    %s %s\n", msg->method, uri->path);
+       debug_printf (2, "    %s %s\n", msg->method, g_uri_get_path (uri));
 
        if ((*treq)->method && !(*treq)->repeat)
                (*treq)++;
@@ -154,13 +154,13 @@ restarted (SoupMessage *msg, gpointer user_data)
                          "Expected to be done");
 
        g_assert_cmpstr (msg->method, ==, (*treq)->method);
-       g_assert_cmpstr (uri->path, ==, (*treq)->path);
+       g_assert_cmpstr (g_uri_get_path (uri), ==, (*treq)->path);
 }
 
 static void
 do_message_api_test (SoupSession *session, TestCase *test)
 {
-       SoupURI *uri;
+       GUri *uri;
        SoupMessage *msg;
        GBytes *body;
        TestRequest *treq;
@@ -168,9 +168,9 @@ do_message_api_test (SoupSession *session, TestCase *test)
        if (test->bugref)
                g_test_bug (test->bugref);
 
-       uri = soup_uri_new_with_base (base_uri, test->requests[0].path);
-       msg = soup_message_new_from_uri (test->requests[0].method, uri);
-       soup_uri_free (uri);
+       uri = g_uri_parse_relative (base_uri, test->requests[0].path, SOUP_HTTP_URI_FLAGS | 
G_URI_FLAGS_PARSE_RELAXED, NULL);
+        msg = soup_message_new_from_uri (test->requests[0].method, uri);
+       g_uri_unref (uri);
 
        if (msg->method == SOUP_METHOD_POST) {
                GBytes *request_body;
@@ -197,7 +197,7 @@ do_message_api_test (SoupSession *session, TestCase *test)
 static void
 do_request_api_test (SoupSession *session, TestCase *test)
 {
-       SoupURI *uri;
+       GUri *uri;
        SoupRequestHTTP *reqh;
        SoupMessage *msg;
        TestRequest *treq;
@@ -207,11 +207,11 @@ do_request_api_test (SoupSession *session, TestCase *test)
        if (test->bugref)
                g_test_bug (test->bugref);
 
-       uri = soup_uri_new_with_base (base_uri, test->requests[0].path);
+       uri = g_uri_parse_relative (base_uri, test->requests[0].path, SOUP_HTTP_URI_FLAGS | 
G_URI_FLAGS_PARSE_RELAXED, NULL);
        reqh = soup_session_request_http_uri (session,
                                              test->requests[0].method,
                                              uri, &error);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        g_assert_no_error (error);
        if (error) {
                g_error_free (error);
@@ -318,7 +318,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
                        soup_message_headers_replace (msg->response_headers,
                                                      "Location",
                                                      "about:blank");
-               } else if (!strcmp (path, "/bad with spaces"))
+               } else if (!strcmp (path, "/bad%20with%20spaces"))
                        soup_message_set_status (msg, SOUP_STATUS_OK);
                else
                        soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND);
@@ -388,7 +388,7 @@ main (int argc, char **argv)
 {
        GMainLoop *loop;
        SoupServer *server, *server2;
-       SoupURI *uri2;
+       GUri *uri2, *uri2_with_path;
        char *path;
        int n, ret;
 
@@ -403,9 +403,10 @@ main (int argc, char **argv)
        soup_server_add_handler (server2, NULL,
                                 server2_callback, NULL, NULL);
        uri2 = soup_test_server_get_uri (server2, "http", NULL);
-       soup_uri_set_path (uri2, "/on-server2");
-       server2_uri = soup_uri_to_string (uri2, FALSE);
-       soup_uri_free (uri2);
+        uri2_with_path = g_uri_parse_relative (uri2, "/on-server2", SOUP_HTTP_URI_FLAGS, NULL);
+        g_uri_unref (uri2);
+       server2_uri = g_uri_to_string (uri2_with_path);
+       g_uri_unref (uri2_with_path);
 
        loop = g_main_loop_new (NULL, TRUE);
 
@@ -429,7 +430,7 @@ main (int argc, char **argv)
        ret = g_test_run ();
 
        g_main_loop_unref (loop);
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
        soup_test_server_quit_unref (server);
        g_free (server2_uri);
        soup_test_server_quit_unref (server2);
diff --git a/tests/request-body-test.c b/tests/request-body-test.c
index fb5cd31d..72764b66 100644
--- a/tests/request-body-test.c
+++ b/tests/request-body-test.c
@@ -7,7 +7,7 @@
 #include "test-utils.h"
 
 static SoupSession *session;
-static SoupURI *base_uri;
+static GUri *base_uri;
 
 typedef struct {
         SoupSession *session;
@@ -89,16 +89,16 @@ static void
 do_request_test (gconstpointer data)
 {
         RequestTestFlags flags = GPOINTER_TO_UINT (data);
-        SoupURI *uri;
+        GUri *uri;
         PutTestData ptd;
         SoupMessage *msg;
         const char *client_md5, *server_md5;
         GChecksum *check;
 
         if (flags & RESTART)
-                uri = soup_uri_new_with_base (base_uri, "/redirect");
+                uri = g_uri_parse_relative (base_uri, "/redirect", SOUP_HTTP_URI_FLAGS, NULL);
         else
-                uri = soup_uri_copy (base_uri);
+                uri = g_uri_ref (base_uri);
 
         ptd.session = session;
         check = setup_request_body (&ptd, flags);
@@ -133,8 +133,7 @@ do_request_test (gconstpointer data)
         g_clear_object (&ptd.stream);
         g_object_unref (msg);
         g_checksum_free (check);
-
-        soup_uri_free (uri);
+        g_uri_unref (uri);
 }
 
 static void
@@ -201,7 +200,7 @@ main (int argc, char **argv)
 
         soup_test_session_abort_unref (session);
 
-        soup_uri_free (base_uri);
+        g_uri_unref (base_uri);
 
         g_main_loop_unref (loop);
         soup_test_server_quit_unref (server);
diff --git a/tests/samesite-test.c b/tests/samesite-test.c
index 0b081b2b..aed12aa0 100644
--- a/tests/samesite-test.c
+++ b/tests/samesite-test.c
@@ -3,8 +3,8 @@
 #include "test-utils.h"
 
 typedef struct {
-       SoupURI *origin_uri;
-       SoupURI *cross_uri;
+       GUri *origin_uri;
+       GUri *cross_uri;
        SoupCookieJar *jar;
        GSList *cookies;
 } SameSiteFixture;
@@ -15,8 +15,8 @@ same_site_setup (SameSiteFixture *fixture,
 {
        SoupCookie *cookie_none, *cookie_lax, *cookie_strict;
 
-       fixture->origin_uri = soup_uri_new ("http://127.0.0.1";);
-       fixture->cross_uri = soup_uri_new ("http://localhost";);
+       fixture->origin_uri = g_uri_parse ("http://127.0.0.1";, SOUP_HTTP_URI_FLAGS, NULL);
+       fixture->cross_uri = g_uri_parse ("http://localhost";, SOUP_HTTP_URI_FLAGS, NULL);
        fixture->jar = soup_cookie_jar_new ();
 
        cookie_none = soup_cookie_new ("none", "1", "127.0.0.1", "/", 1000);
@@ -35,8 +35,8 @@ same_site_teardown (SameSiteFixture *fixture,
                     gconstpointer    data)
 {
        g_object_unref (fixture->jar);
-       soup_uri_free (fixture->origin_uri);
-       soup_uri_free (fixture->cross_uri);
+       g_uri_unref (fixture->origin_uri);
+       g_uri_unref (fixture->cross_uri);
        g_slist_free_full (fixture->cookies, (GDestroyNotify) soup_cookie_free);
 }
 
diff --git a/tests/server-auth-test.c b/tests/server-auth-test.c
index dd92f1a6..350ee933 100644
--- a/tests/server-auth-test.c
+++ b/tests/server-auth-test.c
@@ -5,7 +5,7 @@
 
 #include "test-utils.h"
 
-static SoupURI *base_uri;
+static GUri *base_uri;
 
 static struct {
        gboolean client_sent_basic, client_sent_digest;
@@ -23,26 +23,24 @@ curl_exited (GPid pid, int status, gpointer data)
 }
 
 static void
-do_test (SoupURI *base_uri, const char *path,
+do_test (GUri *base_uri, const char *path,
         gboolean good_user, gboolean good_password,
         gboolean offer_basic, gboolean offer_digest,
         gboolean client_sends_basic, gboolean client_sends_digest,
         gboolean server_requests_basic, gboolean server_requests_digest,
         gboolean success)
 {
-       SoupURI *uri;
+       GUri *uri;
        char *uri_str;
        GPtrArray *args;
        GPid pid;
        gboolean done;
 
-       /* We build the URI this way to avoid having soup_uri_new()
-          normalize the path, hence losing the encoded characters in
-          tests 4. and 5. below. */
-       uri = soup_uri_copy (base_uri);
-       soup_uri_set_path (uri, path);
-       uri_str = soup_uri_to_string (uri, FALSE);
-       soup_uri_free (uri);
+       /* Note that we purposefully do not pass G_URI_FLAGS_ENCODED_PATH here which would lose
+           the encoded characters in tests 4. and 5. below. */
+        uri = g_uri_parse_relative (base_uri, path, G_URI_FLAGS_NONE, NULL);
+       uri_str = g_uri_to_string (uri);
+       g_uri_unref (uri);
 
        args = g_ptr_array_new ();
        g_ptr_array_add (args, "curl");
@@ -386,11 +384,11 @@ main (int argc, char **argv)
 
                ret = g_test_run ();
        } else {
-               g_print ("Listening on port %d\n", base_uri->port);
+               g_print ("Listening on port %d\n", g_uri_get_port (base_uri));
                g_main_loop_run (loop);
                ret = 0;
        }
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
 
        g_main_loop_unref (loop);
        soup_test_server_quit_unref (server);
diff --git a/tests/server-test.c b/tests/server-test.c
index 3c5a1cab..f28e323a 100644
--- a/tests/server-test.c
+++ b/tests/server-test.c
@@ -9,7 +9,7 @@
 
 typedef struct {
        SoupServer *server;
-       SoupURI *base_uri, *ssl_base_uri;
+       GUri *base_uri, *ssl_base_uri;
        GSList *handlers;
 } ServerData;
 
@@ -85,8 +85,8 @@ server_teardown (ServerData *sd, gconstpointer test_data)
        g_slist_free_full (sd->handlers, g_free);
 
        g_clear_pointer (&sd->server, soup_test_server_quit_unref);
-       g_clear_pointer (&sd->base_uri, soup_uri_free);
-       g_clear_pointer (&sd->ssl_base_uri, soup_uri_free);
+       g_clear_pointer (&sd->base_uri, g_uri_unref);
+       g_clear_pointer (&sd->ssl_base_uri, g_uri_unref);
 }
 
 static void
@@ -119,14 +119,16 @@ do_star_test (ServerData *sd, gconstpointer test_data)
 {
        SoupSession *session;
        SoupMessage *msg;
-       SoupURI *star_uri;
+       GUri *star_uri;
        const char *handled_by;
 
        g_test_bug ("590751");
 
+        g_test_skip ("The literal path \"*\" is not a valid GUri");
+        return;
+
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
-       star_uri = soup_uri_copy (sd->base_uri);
-       soup_uri_set_path (star_uri, "*");
+        star_uri = g_uri_parse_relative (sd->base_uri, "*", SOUP_HTTP_URI_FLAGS, NULL);
 
        debug_printf (1, "  Testing with no handler\n");
        msg = soup_message_new_from_uri ("OPTIONS", star_uri);
@@ -151,11 +153,11 @@ do_star_test (ServerData *sd, gconstpointer test_data)
        g_object_unref (msg);
 
        soup_test_session_abort_unref (session);
-       soup_uri_free (star_uri);
+       g_uri_unref (star_uri);
 }
 
 static void
-do_one_server_aliases_test (SoupURI    *uri,
+do_one_server_aliases_test (GUri       *uri,
                            const char *alias,
                            gboolean    succeed)
 {
@@ -168,18 +170,18 @@ do_one_server_aliases_test (SoupURI    *uri,
        GString *req;
        static char buf[1024];
 
-       debug_printf (1, "  %s via %s\n", alias, uri->scheme);
+       debug_printf (1, "  %s via %s\n", alias, g_uri_get_scheme (uri));
 
        /* There's no way to make libsoup's client side send an absolute
         * URI (to a non-proxy server), so we have to fake this.
         */
 
        client = g_socket_client_new ();
-       if (uri->scheme == SOUP_URI_SCHEME_HTTPS) {
+       if (soup_uri_is_https (uri, NULL)) {
                g_socket_client_set_tls (client, TRUE);
                g_socket_client_set_tls_validation_flags (client, 0);
        }
-       addr = g_network_address_new (uri->host, uri->port);
+       addr = g_network_address_new (g_uri_get_host (uri), g_uri_get_port (uri));
 
        conn = g_socket_client_connect (client, addr, NULL, &error);
        g_object_unref (addr);
@@ -195,9 +197,9 @@ do_one_server_aliases_test (SoupURI    *uri,
 
        req = g_string_new (NULL);
        g_string_append_printf (req, "GET %s://%s:%d HTTP/1.1\r\n",
-                               alias, uri->host, uri->port);
+                               alias, g_uri_get_host (uri), g_uri_get_port (uri));
        g_string_append_printf (req, "Host: %s:%d\r\n",
-                               uri->host, uri->port);
+                               g_uri_get_host (uri), g_uri_get_port (uri));
        g_string_append (req, "Connection: close\r\n\r\n");
 
        if (!g_output_stream_write_all (out, req->str, req->len, NULL, NULL, &error)) {
@@ -261,80 +263,80 @@ do_dot_dot_test (ServerData *sd, gconstpointer test_data)
 {
        SoupSession *session;
        SoupMessage *msg;
-       SoupURI *uri;
+       GUri *uri;
 
        g_test_bug ("667635");
 
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
 
-       uri = soup_uri_new_with_base (sd->base_uri, "/..%2ftest");
+       uri = g_uri_parse_relative (sd->base_uri, "/..%2ftest", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        soup_test_session_send_message (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST);
        g_object_unref (msg);
 
-       uri = soup_uri_new_with_base (sd->base_uri, "/%2e%2e%2ftest");
+       uri = g_uri_parse_relative (sd->base_uri, "/%2e%2e%2ftest", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        soup_test_session_send_message (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST);
        g_object_unref (msg);
 
 #ifdef G_OS_WIN32
-       uri = soup_uri_new_with_base (sd->base_uri, "\\..%5Ctest");
+       uri = g_uri_parse_relative (sd->base_uri, "\\..%5Ctest", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        soup_test_session_send_message (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST);
        g_object_unref (msg);
 
-       uri = soup_uri_new_with_base (sd->base_uri, "\\../test");
+       uri = g_uri_parse_relative (sd->base_uri, "\\../test", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        soup_test_session_send_message (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST);
        g_object_unref (msg);
 
-       uri = soup_uri_new_with_base (sd->base_uri, "%5C..%2ftest");
+       uri = g_uri_parse_relative (sd->base_uri, "%5C..%2ftest", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        soup_test_session_send_message (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST);
        g_object_unref (msg);
 
-       uri = soup_uri_new_with_base (sd->base_uri, "/..\\test");
+       uri = g_uri_parse_relative (sd->base_uri, "/..\\test", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        soup_test_session_send_message (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST);
        g_object_unref (msg);
 
-       uri = soup_uri_new_with_base (sd->base_uri, "%2f..%5Ctest");
+       uri = g_uri_parse_relative (sd->base_uri, "%2f..%5Ctest", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        soup_test_session_send_message (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST);
        g_object_unref (msg);
 
-       uri = soup_uri_new_with_base (sd->base_uri, "\\%2e%2e%5ctest");
+       uri = g_uri_parse_relative (sd->base_uri, "\\%2e%2e%5ctest", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        soup_test_session_send_message (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST);
        g_object_unref (msg);
 
-       uri = soup_uri_new_with_base (sd->base_uri, "\\..%%35%63..%%35%63test");
+       uri = g_uri_parse_relative (sd->base_uri, "\\..%%35%63..%%35%63test", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        soup_test_session_send_message (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST);
@@ -419,20 +421,20 @@ multi_server_callback (SoupServer *server, SoupMessage *msg,
 {
        GSocketAddress *addr;
        GInetSocketAddress *iaddr;
-       SoupURI *uri;
+       GUri *uri;
        char *uristr, *addrstr;
 
        addr = soup_client_context_get_local_address (context);
        iaddr = G_INET_SOCKET_ADDRESS (addr);
 
        uri = soup_message_get_uri (msg);
-       uristr = soup_uri_to_string (uri, FALSE);
+       uristr = g_uri_to_string (uri);
 
        addrstr = g_inet_address_to_string (g_inet_socket_address_get_address (iaddr));
-       g_assert_cmpstr (addrstr, ==, uri->host);
+       g_assert_cmpstr (addrstr, ==, g_uri_get_host (uri));
        g_free (addrstr);
 
-       g_assert_cmpint (g_inet_socket_address_get_port (iaddr), ==, uri->port);
+       g_assert_cmpint (g_inet_socket_address_get_port (iaddr), ==, g_uri_get_port (uri));
 
        /* FIXME ssl */
 
@@ -442,7 +444,7 @@ multi_server_callback (SoupServer *server, SoupMessage *msg,
 }
 
 static void
-do_multi_test (ServerData *sd, SoupURI *uri1, SoupURI *uri2)
+do_multi_test (ServerData *sd, GUri *uri1, GUri *uri2)
 {
        char *uristr;
        SoupSession *session;
@@ -453,7 +455,7 @@ do_multi_test (ServerData *sd, SoupURI *uri1, SoupURI *uri2)
 
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
 
-       uristr = soup_uri_to_string (uri1, FALSE);
+       uristr = g_uri_to_string (uri1);
        msg = soup_message_new ("GET", uristr);
        body = soup_test_session_async_send (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
@@ -462,7 +464,7 @@ do_multi_test (ServerData *sd, SoupURI *uri1, SoupURI *uri2)
        g_object_unref (msg);
        g_free (uristr);
 
-       uristr = soup_uri_to_string (uri2, FALSE);
+       uristr = g_uri_to_string (uri2);
        msg = soup_message_new ("GET", uristr);
        body = soup_test_session_async_send (session, msg);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
@@ -473,15 +475,15 @@ do_multi_test (ServerData *sd, SoupURI *uri1, SoupURI *uri2)
 
        soup_test_session_abort_unref (session);
 
-       soup_uri_free (uri1);
-       soup_uri_free (uri2);
+       g_uri_unref (uri1);
+       g_uri_unref (uri2);
 }
 
 static void
 do_multi_port_test (ServerData *sd, gconstpointer test_data)
 {
        GSList *uris;
-       SoupURI *uri1, *uri2;
+       GUri *uri1, *uri2;
        GError *error = NULL;
 
        sd->server = soup_test_server_new (SOUP_TEST_SERVER_NO_DEFAULT_LISTENER);
@@ -503,7 +505,7 @@ do_multi_port_test (ServerData *sd, gconstpointer test_data)
        uri2 = uris->next->data;
        g_slist_free (uris);
 
-       g_assert_cmpint (uri1->port, !=, uri2->port);
+       g_assert_cmpint (g_uri_get_port (uri1), !=, g_uri_get_port (uri2));
 
        do_multi_test (sd, uri1, uri2);
 }
@@ -512,7 +514,7 @@ static void
 do_multi_scheme_test (ServerData *sd, gconstpointer test_data)
 {
        GSList *uris;
-       SoupURI *uri1, *uri2;
+       GUri *uri1, *uri2;
        GError *error = NULL;
 
        SOUP_TEST_SKIP_IF_NO_TLS;
@@ -538,7 +540,7 @@ do_multi_scheme_test (ServerData *sd, gconstpointer test_data)
        uri2 = uris->next->data;
        g_slist_free (uris);
 
-       g_assert_cmpstr (uri1->scheme, !=, uri2->scheme);
+       g_assert_cmpstr (g_uri_get_scheme (uri1), !=, g_uri_get_scheme (uri2));
 
        do_multi_test (sd, uri1, uri2);
 }
@@ -547,7 +549,7 @@ static void
 do_multi_family_test (ServerData *sd, gconstpointer test_data)
 {
        GSList *uris;
-       SoupURI *uri1, *uri2;
+       GUri *uri1, *uri2;
        GError *error = NULL;
 
        sd->server = soup_test_server_new (SOUP_TEST_SERVER_NO_DEFAULT_LISTENER);
@@ -578,8 +580,8 @@ do_multi_family_test (ServerData *sd, gconstpointer test_data)
        uri2 = uris->next->data;
        g_slist_free (uris);
 
-       g_assert_cmpstr (uri1->host, !=, uri2->host);
-       g_assert_cmpint (uri1->port, ==, uri2->port);
+       g_assert_cmpstr (g_uri_get_host (uri1), !=, g_uri_get_host (uri2));
+       g_assert_cmpint (g_uri_get_port (uri1), ==, g_uri_get_port (uri2));
 
        do_multi_test (sd, uri1, uri2);
 }
@@ -591,7 +593,7 @@ do_gsocket_import_test (void)
        GSocketAddress *gaddr;
        SoupServer *server;
        GSList *listeners;
-       SoupURI *uri;
+       GUri *uri;
        SoupSession *session;
        SoupMessage *msg;
        GBytes *body;
@@ -642,7 +644,7 @@ do_gsocket_import_test (void)
 
        soup_test_session_abort_unref (session);
 
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        soup_test_server_quit_unref (server);
 
        g_assert_false (g_socket_is_connected (gsock));
@@ -656,7 +658,7 @@ do_fd_import_test (void)
        GSocketAddress *gaddr;
        SoupServer *server;
        GSList *listeners;
-       SoupURI *uri;
+       GUri *uri;
        SoupSession *session;
        SoupMessage *msg;
        GBytes *body;
@@ -708,7 +710,7 @@ do_fd_import_test (void)
 
        soup_test_session_abort_unref (session);
 
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        soup_test_server_quit_unref (server);
 
        /* @server should have closed our socket, note the specific error isn't reliable */
@@ -1029,7 +1031,7 @@ do_early_respond_test (ServerData *sd, gconstpointer test_data)
 {
        SoupSession *session;
        SoupMessage *msg;
-       SoupURI *uri2;
+       GUri *uri2;
        GBytes *body;
 
        server_add_early_handler (sd, NULL, early_respond_callback, NULL, NULL);
@@ -1044,14 +1046,14 @@ do_early_respond_test (ServerData *sd, gconstpointer test_data)
        g_object_unref (msg);
 
        /* The early handler will ignore this one */
-       uri2 = soup_uri_new_with_base (sd->base_uri, "/subdir");
+       uri2 = g_uri_parse_relative (sd->base_uri, "/subdir", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri2);
        body = soup_test_session_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_assert_cmpmem ("index", sizeof ("index") - 1, g_bytes_get_data (body, NULL), g_bytes_get_size 
(body));
        g_bytes_unref (body);
        g_object_unref (msg);
-       soup_uri_free (uri2);
+       g_uri_unref (uri2);
 
        soup_test_session_abort_unref (session);
 }
@@ -1069,7 +1071,7 @@ do_early_multi_test (ServerData *sd, gconstpointer test_data)
 {
        SoupSession *session;
        SoupMessage *msg;
-       SoupURI *uri;
+       GUri *uri;
        GBytes *body;
        struct {
                const char *path;
@@ -1100,9 +1102,9 @@ do_early_multi_test (ServerData *sd, gconstpointer test_data)
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
 
        for (i = 0; i < G_N_ELEMENTS (multi_tests); i++) {
-               uri = soup_uri_new_with_base (sd->base_uri, multi_tests[i].path);
+               uri = g_uri_parse_relative (sd->base_uri, multi_tests[i].path, SOUP_HTTP_URI_FLAGS, NULL);
                msg = soup_message_new_from_uri ("GET", uri);
-               soup_uri_free (uri);
+               g_uri_unref (uri);
 
                body = soup_test_session_send (session, msg, NULL, NULL);
 
@@ -1334,7 +1336,7 @@ proxy_server_callback (SoupServer *server, SoupMessage *msg,
                       SoupClientContext *context, gpointer data)
 {
        GSocketClient *sclient;
-       SoupURI *dest_uri;
+       GUri *dest_uri;
        Tunnel *tunnel;
 
        if (msg->method != SOUP_METHOD_CONNECT) {
@@ -1351,7 +1353,7 @@ proxy_server_callback (SoupServer *server, SoupMessage *msg,
 
        dest_uri = soup_message_get_uri (msg);
        sclient = g_socket_client_new ();
-       g_socket_client_connect_to_host_async (sclient, dest_uri->host, dest_uri->port,
+       g_socket_client_connect_to_host_async (sclient, g_uri_get_host (dest_uri), g_uri_get_port (dest_uri),
                                               NULL, tunnel_connected_cb, tunnel);
        g_object_unref (sclient);
 }
@@ -1362,7 +1364,7 @@ do_steal_connect_test (ServerData *sd, gconstpointer test_data)
        SoupServer *proxy;
        SoupSession *session;
        SoupMessage *msg;
-       SoupURI *proxy_uri;
+       GUri *proxy_uri;
        char *proxy_uri_str;
        GProxyResolver *resolver;
        const char *handled_by;
@@ -1370,8 +1372,8 @@ do_steal_connect_test (ServerData *sd, gconstpointer test_data)
        SOUP_TEST_SKIP_IF_NO_TLS;
 
        proxy = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
-        proxy_uri = soup_test_server_get_uri (proxy, SOUP_URI_SCHEME_HTTP, "127.0.0.1");
-       proxy_uri_str = soup_uri_to_string (proxy_uri, FALSE);
+        proxy_uri = soup_test_server_get_uri (proxy, "http", "127.0.0.1");
+       proxy_uri_str = g_uri_to_string (proxy_uri);
        soup_server_add_handler (proxy, NULL, proxy_server_callback, NULL, NULL);
 
        resolver = g_simple_proxy_resolver_new (proxy_uri_str, NULL);
@@ -1390,7 +1392,7 @@ do_steal_connect_test (ServerData *sd, gconstpointer test_data)
 
        soup_test_server_quit_unref (proxy);
        g_object_unref (resolver);
-       soup_uri_free (proxy_uri);
+       g_uri_unref (proxy_uri);
        g_free (proxy_uri_str);
 }
 
diff --git a/tests/session-test.c b/tests/session-test.c
index a3952f7d..c715cfe6 100644
--- a/tests/session-test.c
+++ b/tests/session-test.c
@@ -56,7 +56,7 @@ cancel_message_cb (SoupMessage *msg, gpointer session)
 }
 
 static void
-do_test_for_session (SoupSession *session, SoupURI *uri,
+do_test_for_session (SoupSession *session, GUri *uri,
                     gboolean queue_is_async,
                     gboolean send_is_blocking,
                     gboolean cancel_is_immediate)
@@ -64,17 +64,16 @@ do_test_for_session (SoupSession *session, SoupURI *uri,
        SoupMessage *msg;
        gboolean finished, local_timeout;
        guint timeout_id;
-       SoupURI *timeout_uri;
+       GUri *timeout_uri;
        GBytes *body;
 
        debug_printf (1, "  queue_message\n");
        debug_printf (2, "    requesting timeout\n");
-       timeout_uri = soup_uri_new_with_base (uri, "/request-timeout");
+       timeout_uri = g_uri_parse_relative (uri, "/request-timeout", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", timeout_uri);
-       soup_uri_free (timeout_uri);
        body = soup_test_session_send (session, msg, NULL, NULL);
        g_bytes_unref (body);
-       g_object_unref (msg);
+       g_uri_unref (timeout_uri);
 
        msg = soup_message_new_from_uri ("GET", uri);
        server_processed_message = timeout = finished = FALSE;
@@ -159,7 +158,7 @@ do_test_for_session (SoupSession *session, SoupURI *uri,
 static void
 do_plain_tests (gconstpointer data)
 {
-       SoupURI *uri = (SoupURI *)data;
+       GUri *uri = (GUri *)data;
        SoupSession *session;
 
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
@@ -186,7 +185,7 @@ priority_test_finished_cb (SoupMessage *msg,
 static void
 do_priority_tests (gconstpointer data)
 {
-       SoupURI *uri = (SoupURI *)data;
+       GUri *uri = (GUri *)data;
        SoupSession *session;
        int i, finished_count = 0;
        SoupMessagePriority priorities[] =
@@ -204,14 +203,14 @@ do_priority_tests (gconstpointer data)
        expected_priorities[2] = SOUP_MESSAGE_PRIORITY_LOW;
 
        for (i = 0; i < 3; i++) {
-               SoupURI *msg_uri;
+               GUri *msg_uri;
                SoupMessage *msg;
                char buf[5];
 
                g_snprintf (buf, sizeof (buf), "%d", i);
-               msg_uri = soup_uri_new_with_base (uri, buf);
+               msg_uri = g_uri_parse_relative (uri, buf, SOUP_HTTP_URI_FLAGS, NULL);
                msg = soup_message_new_from_uri ("GET", msg_uri);
-               soup_uri_free (msg_uri);
+               g_uri_unref (msg_uri);
 
                soup_message_set_priority (msg, priorities[i]);
                g_signal_connect (msg, "finished",
@@ -374,7 +373,7 @@ int
 main (int argc, char **argv)
 {
        SoupServer *server;
-       SoupURI *uri;
+       GUri *uri;
        int ret;
 
        test_init (argc, argv, NULL);
@@ -390,7 +389,7 @@ main (int argc, char **argv)
 
        ret = g_test_run ();
 
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
diff --git a/tests/sniffing-test.c b/tests/sniffing-test.c
index 98547a34..156af354 100644
--- a/tests/sniffing-test.c
+++ b/tests/sniffing-test.c
@@ -6,7 +6,7 @@
 #include "test-utils.h"
 
 SoupSession *session;
-SoupURI *base_uri;
+GUri *base_uri;
 SoupMessageBody *chunk_data;
 
 static void
@@ -87,7 +87,6 @@ server_callback (SoupServer *server, SoupMessage *msg,
 
        if (g_str_has_prefix (path, "/type/")) {
                char **components = g_strsplit (path, "/", 4);
-               char *ptr;
 
                char *base_name = g_path_get_basename (path);
 
@@ -95,13 +94,12 @@ server_callback (SoupServer *server, SoupMessage *msg,
                g_assert_no_error (error);
                g_free (base_name);
 
-               /* Hack to allow passing type in the URI */
-               ptr = g_strrstr (components[2], "_");
-               *ptr = '/';
-
+               /* We had to escape the type strings to pass through a URI */
+                char *type = g_uri_unescape_string (components[2], NULL);
                soup_message_headers_append (msg->response_headers,
-                                            "Content-Type", components[2]);
+                                            "Content-Type", type);
                g_strfreev (components);
+                g_free (type);
        }
 
        if (g_str_has_prefix (path, "/multiple_headers/")) {
@@ -195,6 +193,23 @@ got_chunk (SoupMessage *msg, GBytes *chunk, gpointer data)
        }
 }
 
+static GUri *
+uri_set_query (GUri *uri, const char *query)
+{
+        GUri *new_uri = g_uri_build (
+                g_uri_get_flags (uri),
+                g_uri_get_scheme (uri),
+                NULL,
+                g_uri_get_host (uri),
+                g_uri_get_port (uri),
+                g_uri_get_path (uri),
+                query,
+                g_uri_get_fragment (uri)
+        );
+        g_uri_unref (uri);
+        return new_uri;
+}
+
 static void
 do_signals_test (gboolean should_content_sniff,
                 gboolean should_pause,
@@ -202,7 +217,7 @@ do_signals_test (gboolean should_content_sniff,
                 gboolean chunked_encoding,
                 gboolean empty_response)
 {
-       SoupURI *uri = soup_uri_new_with_base (base_uri, "/mbox");
+       GUri *uri = g_uri_parse_relative (base_uri, "/mbox", SOUP_HTTP_URI_FLAGS, NULL);
        SoupMessage *msg = soup_message_new_from_uri ("GET", uri);
        GBytes *expected;
        GError *error = NULL;
@@ -216,15 +231,15 @@ do_signals_test (gboolean should_content_sniff,
                      empty_response ? "" : "!");
 
        if (chunked_encoding)
-               soup_uri_set_query (uri, "chunked=yes");
+                uri = uri_set_query (uri, "chunked=yes");
 
        if (empty_response) {
-               if (uri->query) {
-                       char *tmp = uri->query;
-                       uri->query = g_strdup_printf ("%s&empty_response=yes", tmp);
-                       g_free (tmp);
+               if (g_uri_get_query (uri)) {
+                       char *new_query = g_strdup_printf ("%s&empty_response=yes", g_uri_get_query (uri));
+                        uri = uri_set_query (uri, new_query);
+                       g_free (new_query);
                } else
-                       soup_uri_set_query (uri, "empty_response=yes");
+                       uri_set_query (uri, "empty_response=yes");
        }
 
        soup_message_set_uri (msg, uri);
@@ -261,16 +276,13 @@ do_signals_test (gboolean should_content_sniff,
        else if (msg->response_body)
                body = soup_message_body_flatten (msg->response_body);
 
-       if (body) {
-                //g_message ("|||body (%zu): %s", g_bytes_get_size (body), (char*)g_bytes_get_data (body, 
NULL));
-                //g_message ("|||expected (%zu): %s", g_bytes_get_size (expected), (char*)g_bytes_get_data 
(expected, NULL));
+       if (body)
                 g_assert_true (g_bytes_equal (body, expected));
-       }
 
        g_bytes_unref (expected);
        g_bytes_unref (body);
         g_clear_pointer (&chunk_data, soup_message_body_free);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        g_object_unref (msg);
 }
 
@@ -339,7 +351,7 @@ sniffing_content_sniffed (SoupMessage *msg, const char *content_type,
 static void
 test_sniffing (const char *path, const char *expected_type)
 {
-       SoupURI *uri;
+       GUri *uri;
        SoupMessage *msg;
        GBytes *body;
        SoupRequest *req;
@@ -348,7 +360,7 @@ test_sniffing (const char *path, const char *expected_type)
        const char *req_sniffed_type;
        GError *error = NULL;
 
-       uri = soup_uri_new_with_base (base_uri, path);
+       uri = g_uri_parse_relative (base_uri, path, SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
 
        g_signal_connect (msg, "content-sniffed",
@@ -373,7 +385,7 @@ test_sniffing (const char *path, const char *expected_type)
        g_assert_cmpstr (req_sniffed_type, ==, expected_type);
        g_object_unref (req);
 
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 }
 
 static void
@@ -393,7 +405,7 @@ static void
 test_disabled (gconstpointer data)
 {
        const char *path = data;
-       SoupURI *uri;
+       GUri *uri;
        SoupMessage *msg;
        GBytes *body;
        SoupRequest *req;
@@ -404,7 +416,7 @@ test_disabled (gconstpointer data)
 
        g_test_bug ("574773");
 
-       uri = soup_uri_new_with_base (base_uri, path);
+       uri = g_uri_parse_relative (base_uri, path, SOUP_HTTP_URI_FLAGS, NULL);
 
        msg = soup_message_new_from_uri ("GET", uri);
        g_assert_false (soup_message_is_feature_disabled (msg, SOUP_TYPE_CONTENT_SNIFFER));
@@ -438,7 +450,7 @@ test_disabled (gconstpointer data)
 
        g_object_unref (req);
 
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 }
 
 int
@@ -543,55 +555,55 @@ main (int argc, char **argv)
 
        /* Test the XML sniffing path */
        g_test_add_data_func ("/sniffing/type/xml",
-                             "type/text_xml/home.gif => text/xml",
+                             "type/text%2Fxml/home.gif => text/xml",
                              do_sniffing_test);
        g_test_add_data_func ("/sniffing/type/xml+xml",
-                             "type/anice_type+xml/home.gif => anice/type+xml",
+                             "type/anice%2Ftype+xml/home.gif => anice/type+xml",
                              do_sniffing_test);
        g_test_add_data_func ("/sniffing/type/application-xml",
-                             "type/application_xml/home.gif => application/xml",
+                             "type/application%2Fxml/home.gif => application/xml",
                              do_sniffing_test);
 
        /* Test the feed or html path */
        g_test_add_data_func ("/sniffing/type/html/html",
-                             "type/text_html/test.html => text/html",
+                             "type/text%2Fhtml/test.html => text/html",
                              do_sniffing_test);
        g_test_add_data_func ("/sniffing/type/html/rss",
-                             "type/text_html/rss20.xml => application/rss+xml",
+                             "type/text%2Fhtml/rss20.xml => application/rss+xml",
                              do_sniffing_test);
        g_test_add_data_func ("/sniffing/type/html/atom",
-                             "type/text_html/atom.xml => application/atom+xml",
+                             "type/text%2Fhtml/atom.xml => application/atom+xml",
                              do_sniffing_test);
        g_test_add_data_func ("/sniffing/type/html/rdf",
-                             "type/text_html/feed.rdf => application/rss+xml",
+                             "type/text%2Fhtml/feed.rdf => application/rss+xml",
                              do_sniffing_test);
 
        /* Test the image sniffing path */
        g_test_add_data_func ("/sniffing/type/image/gif",
-                             "type/image_png/home.gif => image/gif",
+                             "type/image%2Fpng/home.gif => image/gif",
                              do_sniffing_test);
        g_test_add_data_func ("/sniffing/type/image/png",
-                             "type/image_gif/home.png => image/png",
+                             "type/image%2Fgif/home.png => image/png",
                              do_sniffing_test);
        g_test_add_data_func ("/sniffing/type/image/jpeg",
-                             "type/image_png/home.jpg => image/jpeg",
+                             "type/image%2Fpng/home.jpg => image/jpeg",
                              do_sniffing_test);
        g_test_add_data_func ("/sniffing/type/image/webp",
-                             "type/image_png/tux.webp => image/webp",
+                             "type/image%2Fpng/tux.webp => image/webp",
                              do_sniffing_test);
 
        /* Test audio and video sniffing path */
        g_test_add_data_func ("/sniffing/type/audio/wav",
-                             "type/audio_mpeg/test.wav => audio/wave",
+                             "type/audio%2Fmpeg/test.wav => audio/wave",
                              do_sniffing_test);
        g_test_add_data_func ("/sniffing/type/audio/aiff",
-                             "type/audio_mpeg/test.aiff => audio/aiff",
+                             "type/audio%2Fmpeg/test.aiff => audio/aiff",
                              do_sniffing_test);
        g_test_add_data_func ("/sniffing/type/audio/ogg",
-                             "type/audio_mpeg/test.ogg => application/ogg",
+                             "type/audio%2Fmpeg/test.ogg => application/ogg",
                              do_sniffing_test);
        g_test_add_data_func ("/sniffing/type/video/webm",
-                             "type/video_theora/test.webm => video/webm",
+                             "type/video%2Ftheora/test.webm => video/webm",
                              do_sniffing_test);
 
        /* Test the MP4 sniffing path */
@@ -606,7 +618,7 @@ main (int argc, char **argv)
 
        /* Test that we keep the parameters when sniffing */
        g_test_add_data_func ("/sniffing/parameters",
-                             "type/text_html; charset=UTF-8/test.html => text/html; charset=UTF-8",
+                             "type/text%2Fhtml%3B%20charset=UTF-8/test.html => text/html; charset=UTF-8",
                              do_sniffing_test);
 
        /* Test that disabling the sniffer works correctly */
@@ -616,7 +628,7 @@ main (int argc, char **argv)
 
        ret = g_test_run ();
 
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
 
        soup_test_session_abort_unref (session);
        soup_test_server_quit_unref (server);
diff --git a/tests/socket-test.c b/tests/socket-test.c
index 0fd20529..e6cb5f11 100644
--- a/tests/socket-test.c
+++ b/tests/socket-test.c
@@ -125,7 +125,7 @@ static void
 do_socket_from_fd_client_test (void)
 {
        SoupServer *server;
-       SoupURI *uri;
+       GUri *uri;
        GSocket *gsock;
        SoupSocket *sock;
        GInetSocketAddress *local, *remote;
@@ -142,7 +142,7 @@ do_socket_from_fd_client_test (void)
                              &error);
        g_assert_no_error (error);
 
-       gaddr = g_inet_socket_address_new_from_string ("127.0.0.1", uri->port);
+       gaddr = g_inet_socket_address_new_from_string ("127.0.0.1", g_uri_get_port (uri));
        g_socket_connect (gsock, gaddr, NULL, &error);
        g_object_unref (gaddr);
        g_assert_no_error (error);
@@ -169,7 +169,7 @@ do_socket_from_fd_client_test (void)
        assert_host_equals (local, "127.0.0.1");
        g_assert_cmpint (g_inet_socket_address_get_port (local), ==, g_inet_socket_address_get_port 
(G_INET_SOCKET_ADDRESS (gaddr)));
         assert_host_equals (remote, "127.0.0.1");
-       g_assert_cmpint (g_inet_socket_address_get_port (remote), ==, uri->port);
+       g_assert_cmpint (g_inet_socket_address_get_port (remote), ==, g_uri_get_port (uri));
 
        g_object_unref (local);
        g_object_unref (remote);
@@ -179,7 +179,7 @@ do_socket_from_fd_client_test (void)
        g_object_unref (gsock);
 
        soup_test_server_quit_unref (server);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 }
 
 static void
diff --git a/tests/ssl-test.c b/tests/ssl-test.c
index 1422834a..66e94262 100644
--- a/tests/ssl-test.c
+++ b/tests/ssl-test.c
@@ -2,7 +2,7 @@
 
 #include "test-utils.h"
 
-SoupURI *uri;
+GUri *uri;
 
 typedef struct {
        const char *name;
@@ -186,7 +186,7 @@ do_tls_interaction_test (void)
        SoupMessage *msg;
        GBytes *body;
        GTlsInteraction *interaction;
-       SoupURI *test_uri;
+       GUri *test_uri;
        GError *error = NULL;
 
        SOUP_TEST_SKIP_IF_NO_TLS;
@@ -202,8 +202,9 @@ do_tls_interaction_test (void)
        g_signal_connect (service, "run", G_CALLBACK (got_connection), NULL);
        g_socket_service_start (service);
 
-       test_uri = soup_uri_new ("https://127.0.0.1";);
-       soup_uri_set_port (test_uri, g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (bound_address)));
+        test_uri = g_uri_build (SOUP_HTTP_URI_FLAGS, "https", NULL, "127.0.0.1",
+                                g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (bound_address)),
+                                "/", NULL, NULL);
        g_object_unref (bound_address);
 
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
@@ -229,7 +230,7 @@ do_tls_interaction_test (void)
        g_bytes_unref (body);
        g_object_unref (msg);
 
-       soup_uri_free (test_uri);
+       g_uri_unref (test_uri);
        soup_test_session_abort_unref (session);
 
        g_socket_service_stop (service);
@@ -276,7 +277,7 @@ main (int argc, char **argv)
        ret = g_test_run ();
 
        if (tls_available) {
-               soup_uri_free (uri);
+               g_uri_unref (uri);
                soup_test_server_quit_unref (server);
        }
 
diff --git a/tests/streaming-test.c b/tests/streaming-test.c
index b1a10d54..c9557d00 100644
--- a/tests/streaming-test.c
+++ b/tests/streaming-test.c
@@ -73,16 +73,16 @@ server_callback (SoupServer *server, SoupMessage *msg,
 }
 
 static void
-do_request (SoupSession *session, SoupURI *base_uri, char *path)
+do_request (SoupSession *session, GUri *base_uri, char *path)
 {
-       SoupURI *uri;
+       GUri *uri;
        SoupMessage *msg;
        GBytes *body;
        char *md5;
 
-       uri = soup_uri_new_with_base (base_uri, path);
+       uri = g_uri_parse_relative (base_uri, path, SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
 
        body = soup_test_session_async_send (session, msg);
 
@@ -102,7 +102,7 @@ do_request (SoupSession *session, SoupURI *base_uri, char *path)
 static void
 do_chunked_test (gconstpointer data)
 {
-       SoupURI *base_uri = (SoupURI *)data;
+       GUri *base_uri = (GUri *)data;
        SoupSession *session;
 
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
@@ -113,7 +113,7 @@ do_chunked_test (gconstpointer data)
 static void
 do_content_length_test (gconstpointer data)
 {
-       SoupURI *base_uri = (SoupURI *)data;
+       GUri *base_uri = (GUri *)data;
        SoupSession *session;
 
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
@@ -124,7 +124,7 @@ do_content_length_test (gconstpointer data)
 static void
 do_eof_test (gconstpointer data)
 {
-       SoupURI *base_uri = (SoupURI *)data;
+       GUri *base_uri = (GUri *)data;
        SoupSession *session;
 
        g_test_bug ("572153");
@@ -139,7 +139,7 @@ main (int argc, char **argv)
 {
        GMainLoop *loop;
        SoupServer *server;
-       SoupURI *base_uri;
+       GUri *base_uri;
        int ret;
 
        test_init (argc, argv, NULL);
@@ -161,7 +161,7 @@ main (int argc, char **argv)
 
        ret = g_test_run ();
 
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
        g_main_loop_unref (loop);
 
        g_free (full_response_md5);
diff --git a/tests/test-utils.c b/tests/test-utils.c
index 2dacdb3d..d8e9883e 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -460,36 +460,36 @@ soup_test_server_new (SoupTestServerOptions options)
        return server;
 }
 
-static SoupURI *
+static GUri *
 find_server_uri (SoupServer *server, const char *scheme, const char *host)
 {
        GSList *uris, *u;
-       SoupURI *uri, *ret_uri = NULL;
+       GUri *uri, *ret_uri = NULL;
 
        uris = soup_server_get_uris (server);
        for (u = uris; u; u = u->next) {
                uri = u->data;
 
-               if (scheme && strcmp (uri->scheme, scheme) != 0)
+               if (scheme && strcmp (g_uri_get_scheme (uri), scheme) != 0)
                        continue;
-               if (host && strcmp (uri->host, host) != 0)
+               if (host && strcmp (g_uri_get_host (uri), host) != 0)
                        continue;
 
-               ret_uri = soup_uri_copy (uri);
+               ret_uri = g_uri_ref (uri);
                break;
        }
-       g_slist_free_full (uris, (GDestroyNotify)soup_uri_free);
+       g_slist_free_full (uris, (GDestroyNotify)g_uri_unref);
 
        return ret_uri;
 }
 
-static SoupURI *
+static GUri *
 add_listener (SoupServer *server, const char *scheme, const char *host)
 {
        SoupServerListenOptions options = 0;
        GError *error = NULL;
 
-       if (!g_strcmp0 (scheme, SOUP_URI_SCHEME_HTTPS))
+       if (!g_strcmp0 (scheme, "https"))
                options |= SOUP_SERVER_LISTEN_HTTPS;
        if (!g_strcmp0 (host, "127.0.0.1"))
                options |= SOUP_SERVER_LISTEN_IPV4_ONLY;
@@ -510,7 +510,7 @@ typedef struct {
        const char *scheme;
        const char *host;
 
-       SoupURI *uri;
+       GUri *uri;
 } AddListenerData;
 
 static gboolean
@@ -526,12 +526,12 @@ add_listener_in_thread (gpointer user_data)
        return FALSE;
 }
 
-SoupURI *
+GUri *
 soup_test_server_get_uri (SoupServer    *server,
                          const char    *scheme,
                          const char    *host)
 {
-       SoupURI *uri;
+       GUri *uri;
        GMainLoop *loop;
 
        uri = find_server_uri (server, scheme, host);
@@ -895,3 +895,21 @@ soup_test_assert (gboolean expr, const char *fmt, ...)
        }
 }
 #endif
+
+GUri *
+soup_test_uri_set_port (GUri *uri, int port)
+{
+        GUri *new_uri = g_uri_build_with_user (
+                g_uri_get_flags (uri),
+                g_uri_get_scheme (uri),
+                g_uri_get_user (uri),
+                g_uri_get_password (uri),
+                g_uri_get_auth_params (uri),
+                g_uri_get_host (uri),
+                port,
+                g_uri_get_path (uri),
+                g_uri_get_query (uri),
+                g_uri_get_fragment (uri)
+        );
+        return new_uri;
+}
diff --git a/tests/test-utils.h b/tests/test-utils.h
index 64ac71ad..8234c44b 100644
--- a/tests/test-utils.h
+++ b/tests/test-utils.h
@@ -65,7 +65,7 @@ typedef enum {
 } SoupTestServerOptions;
 
 SoupServer  *soup_test_server_new            (SoupTestServerOptions  options);
-SoupURI     *soup_test_server_get_uri        (SoupServer            *server,
+GUri        *soup_test_server_get_uri        (SoupServer            *server,
                                              const char            *scheme,
                                              const char            *host);
 void         soup_test_server_quit_unref     (SoupServer            *server);
@@ -93,6 +93,9 @@ GBytes     *soup_test_load_resource      (const char  *name,
 
 GBytes     *soup_test_get_index          (void);
 
+GUri       *soup_test_uri_set_port       (GUri *uri,
+                                          int   port);
+
 #ifdef G_HAVE_ISO_VARARGS
 #define soup_test_assert(expr, ...)                            \
 G_STMT_START {                                                         \
diff --git a/tests/timeout-test.c b/tests/timeout-test.c
index 17977434..edb9a813 100644
--- a/tests/timeout-test.c
+++ b/tests/timeout-test.c
@@ -24,7 +24,7 @@ request_started_cb (SoupSession *session, SoupMessage *msg, gpointer user_data)
 }
 
 static void
-do_message_to_session (SoupSession *session, SoupURI *uri,
+do_message_to_session (SoupSession *session, GUri *uri,
                       const char *comment, guint expected_status)
 {
        SoupMessage *msg;
@@ -55,8 +55,8 @@ static void
 do_msg_tests_for_session (SoupSession *timeout_session,
                          SoupSession *idle_session,
                          SoupSession *plain_session,
-                         SoupURI *fast_uri,
-                         SoupURI *slow_uri)
+                         GUri *fast_uri,
+                         GUri *slow_uri)
 {
        SoupSocket *ret, *idle_first = NULL, *idle_second;
        SoupSocket *plain_first = NULL, *plain_second;
@@ -104,7 +104,7 @@ do_msg_tests_for_session (SoupSession *timeout_session,
 }
 
 static void
-do_request_to_session (SoupSession *session, SoupURI *uri,
+do_request_to_session (SoupSession *session, GUri *uri,
                       const char *comment, gboolean expect_timeout)
 {
        SoupRequest *req;
@@ -153,8 +153,8 @@ static void
 do_req_tests_for_session (SoupSession *timeout_session,
                          SoupSession *idle_session,
                          SoupSession *plain_session,
-                         SoupURI *fast_uri,
-                         SoupURI *slow_uri)
+                         GUri *fast_uri,
+                         GUri *slow_uri)
 {
        SoupSocket *ret, *idle_first = NULL, *idle_second;
        SoupSocket *plain_first = NULL, *plain_second;
@@ -205,16 +205,15 @@ static void
 do_async_timeout_tests (gconstpointer data)
 {
        SoupSession *timeout_session, *idle_session, *plain_session;
-       SoupURI *fast_uri = (SoupURI *)data;
-       SoupURI *slow_uri = soup_uri_new_with_base (fast_uri, "/slow");
+       GUri *fast_uri = (GUri *)data;
+       GUri *slow_uri = g_uri_parse_relative (fast_uri, "/slow", SOUP_HTTP_URI_FLAGS, NULL);
        gboolean extra_slow;
 
        g_test_skip ("FIXME");
        return;
 
-       if (fast_uri->scheme == SOUP_URI_SCHEME_HTTPS) {
+       if (soup_uri_is_https (fast_uri, NULL)) {
                SOUP_TEST_SKIP_IF_NO_TLS;
-
                extra_slow = slow_https;
        } else
                extra_slow = FALSE;
@@ -241,21 +240,21 @@ do_async_timeout_tests (gconstpointer data)
        soup_test_session_abort_unref (idle_session);
        soup_test_session_abort_unref (plain_session);
 
-       soup_uri_free (slow_uri);
+       g_uri_unref (slow_uri);
 }
 
 static void
 do_sync_timeout_tests (gconstpointer data)
 {
        SoupSession *timeout_session, *plain_session;
-       SoupURI *fast_uri = (SoupURI *)data;
-       SoupURI *slow_uri = soup_uri_new_with_base (fast_uri, "/slow");
+       GUri *fast_uri = (GUri *)data;
+       GUri *slow_uri = g_uri_parse_relative (fast_uri, "/slow", SOUP_HTTP_URI_FLAGS, NULL);
        gboolean extra_slow;
 
        g_test_skip ("FIXME");
        return;
 
-       if (fast_uri->scheme == SOUP_URI_SCHEME_HTTPS) {
+       if (soup_uri_is_https (fast_uri, NULL)) {
                SOUP_TEST_SKIP_IF_NO_TLS;
 
                extra_slow = slow_https;
@@ -273,7 +272,7 @@ do_sync_timeout_tests (gconstpointer data)
        soup_test_session_abort_unref (timeout_session);
        soup_test_session_abort_unref (plain_session);
 
-       soup_uri_free (slow_uri);
+       g_uri_unref (slow_uri);
 }
 
 static gboolean
@@ -310,7 +309,7 @@ int
 main (int argc, char **argv)
 {
        SoupServer *server, *https_server = NULL;
-       SoupURI *uri, *https_uri = NULL;
+       GUri *uri, *https_uri = NULL;
        int ret;
 
        test_init (argc, argv, NULL);
@@ -344,7 +343,7 @@ main (int argc, char **argv)
                        slow_https = FALSE;
                }
        } else
-               https_uri = soup_uri_new ("https://fail.";);
+               https_uri = g_uri_parse ("https://fail.";, SOUP_HTTP_URI_FLAGS, NULL);
 
        g_test_add_data_func ("/timeout/http/async", uri, do_async_timeout_tests);
        g_test_add_data_func ("/timeout/http/sync", uri, do_sync_timeout_tests);
@@ -353,8 +352,8 @@ main (int argc, char **argv)
 
        ret = g_test_run ();
 
-       soup_uri_free (uri);
-       soup_uri_free (https_uri);
+       g_uri_unref (uri);
+       g_uri_unref (https_uri);
        soup_test_server_quit_unref (server);
        if (https_server)
                soup_test_server_quit_unref (https_server);
diff --git a/tests/uri-parsing-test.c b/tests/uri-parsing-test.c
index d463f1f4..3b3363b7 100644
--- a/tests/uri-parsing-test.c
+++ b/tests/uri-parsing-test.c
@@ -2,259 +2,280 @@
 
 #include "test-utils.h"
 
+struct UriParts {
+        const char *scheme;
+        const char *user;
+        const char *password;
+        const char *host;
+        const int port;
+        const char *path;
+        const char *query;
+        const char *fragment;
+};
+
 static struct {
        const char *uri_string, *result, *bugref;
-       const SoupURI bits;
+       const struct UriParts bits;
 } abs_tests[] = {
        { "foo:", "foo:", NULL,
-         { "foo", NULL, NULL, NULL, 0, "", NULL, NULL } },
+         { "foo", NULL, NULL, NULL, -1, "", NULL, NULL } },
        { "file:/dev/null", "file:/dev/null", NULL,
-         { "file", NULL, NULL, NULL, 0, "/dev/null", NULL, NULL } },
+         { "file", NULL, NULL, NULL, -1, "/dev/null", NULL, NULL } },
        { "file:///dev/null", "file:///dev/null", NULL,
-         { "file", NULL, NULL, "", 0, "/dev/null", NULL, NULL } },
+         { "file", NULL, NULL, "", -1, "/dev/null", NULL, NULL } },
        { "ftp://user@host/path";, "ftp://user@host/path";, NULL,
-         { "ftp", "user", NULL, "host", 21, "/path", NULL, NULL } },
+         { "ftp", "user", NULL, "host", -1, "/path", NULL, NULL } },
        { "ftp://user@host:9999/path";, "ftp://user@host:9999/path";, NULL,
          { "ftp", "user", NULL, "host", 9999, "/path", NULL, NULL } },
        { "ftp://user:password@host/path";, "ftp://user@host/path";, NULL,
-         { "ftp", "user", "password", "host", 21, "/path", NULL, NULL } },
+         { "ftp", "user", "password", "host", -1, "/path", NULL, NULL } },
        { "ftp://user:password@host:9999/path";, "ftp://user@host:9999/path";, NULL,
          { "ftp", "user", "password", "host", 9999, "/path", NULL, NULL } },
        { "ftp://user:password@host";, "ftp://user@host";, NULL,
-         { "ftp", "user", "password", "host", 21, "", NULL, NULL } },
+         { "ftp", "user", "password", "host", -1, "", NULL, NULL } },
        { "http://us%65r@host";, "http://user@host/";, NULL,
-         { "http", "user", NULL, "host", 80, "/", NULL, NULL } },
+         { "http", "user", NULL, "host", -1,"/", NULL, NULL } },
        { "http://us%40r@host";, "http://us%40r@host/";, NULL,
-         { "http", "us\x40r", NULL, "host", 80, "/", NULL, NULL } },
+         { "http", "us\x40r", NULL, "host", -1,"/", NULL, NULL } },
        { "http://us%3ar@host";, "http://us%3Ar@host/";, NULL,
-         { "http", "us\x3ar", NULL, "host", 80, "/", NULL, NULL } },
+         { "http", "us\x3ar", NULL, "host", -1,"/", NULL, NULL } },
        { "http://us%2fr@host";, "http://us%2Fr@host/";, NULL,
-         { "http", "us\x2fr", NULL, "host", 80, "/", NULL, NULL } },
+         { "http", "us\x2fr", NULL, "host", -1,"/", NULL, NULL } },
        { "http://us%3fr@host";, "http://us%3Fr@host/";, NULL,
-         { "http", "us\x3fr", NULL, "host", 80, "/", NULL, NULL } },
+         { "http", "us\x3fr", NULL, "host", -1,"/", NULL, NULL } },
        { "http://host?query";, "http://host/?query";, NULL,
-         { "http", NULL, NULL, "host", 80, "/", "query", NULL } },
+         { "http", NULL, NULL, "host", -1,"/", "query", NULL } },
        { "http://host/path?query=http%3A%2F%2Fhost%2Fpath%3Fchildparam%3Dchildvalue&param=value";,
          "http://host/path?query=http%3A%2F%2Fhost%2Fpath%3Fchildparam%3Dchildvalue&param=value";, NULL,
-         { "http", NULL, NULL, "host", 80, "/path", 
"query=http%3A%2F%2Fhost%2Fpath%3Fchildparam%3Dchildvalue&param=value", NULL } },
+         { "http", NULL, NULL, "host", -1,"/path", 
"query=http%3A%2F%2Fhost%2Fpath%3Fchildparam%3Dchildvalue&param=value", NULL } },
        { 
"http://control-chars/%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%7F";,
          
"http://control-chars/%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%7F";,
 NULL,
-         { "http", NULL, NULL, "control-chars", 80, 
"/%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%7F", NULL, 
NULL } },
+         { "http", NULL, NULL, "control-chars", 
-1,"/%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%7F", NULL, 
NULL } },
        { "http://space/%20";,
          "http://space/%20";, NULL,
-         { "http", NULL, NULL, "space", 80, "/%20", NULL, NULL } },
+         { "http", NULL, NULL, "space", -1,"/%20", NULL, NULL } },
        { "http://delims/%3C%3E%23%25%22";,
          "http://delims/%3C%3E%23%25%22";, NULL,
-         { "http", NULL, NULL, "delims", 80, "/%3C%3E%23%25%22", NULL, NULL } },
+         { "http", NULL, NULL, "delims", -1,"/%3C%3E%23%25%22", NULL, NULL } },
        { "http://unwise-chars/%7B%7D%7C%5C%5E%5B%5D%60";,
          "http://unwise-chars/%7B%7D%7C%5C%5E%5B%5D%60";, NULL,
-         { "http", NULL, NULL, "unwise-chars", 80, "/%7B%7D%7C%5C%5E%5B%5D%60", NULL, NULL } },
+         { "http", NULL, NULL, "unwise-chars", -1,"/%7B%7D%7C%5C%5E%5B%5D%60", NULL, NULL } },
 
        /* From RFC 2732 */
        { "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html";,
-         "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]/index.html";, NULL,
+         "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html";, NULL,
          { "http", NULL, NULL, "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210", 80, "/index.html", NULL, NULL } },
        { "http://[1080:0:0:0:8:800:200C:417A]/index.html";,
          "http://[1080:0:0:0:8:800:200C:417A]/index.html";, NULL,
-         { "http", NULL, NULL, "1080:0:0:0:8:800:200C:417A", 80, "/index.html", NULL, NULL } },
+         { "http", NULL, NULL, "1080:0:0:0:8:800:200C:417A", -1,"/index.html", NULL, NULL } },
        { "http://[3ffe:2a00:100:7031::1]";,
          "http://[3ffe:2a00:100:7031::1]/";, NULL,
-         { "http", NULL, NULL, "3ffe:2a00:100:7031::1", 80, "/", NULL, NULL } },
+         { "http", NULL, NULL, "3ffe:2a00:100:7031::1", -1,"/", NULL, NULL } },
        { "http://[1080::8:800:200C:417A]/foo";,
          "http://[1080::8:800:200C:417A]/foo";, NULL,
-         { "http", NULL, NULL, "1080::8:800:200C:417A", 80, "/foo", NULL, NULL } },
+         { "http", NULL, NULL, "1080::8:800:200C:417A", -1,"/foo", NULL, NULL } },
        { "http://[::192.9.5.5]/ipng";,
          "http://[::192.9.5.5]/ipng";, NULL,
-         { "http", NULL, NULL, "::192.9.5.5", 80, "/ipng", NULL, NULL } },
+         { "http", NULL, NULL, "::192.9.5.5", -1,"/ipng", NULL, NULL } },
        { "http://[::FFFF:129.144.52.38]:80/index.html";,
-         "http://[::FFFF:129.144.52.38]/index.html";, NULL,
+         "http://[::FFFF:129.144.52.38]:80/index.html";, NULL,
          { "http", NULL, NULL, "::FFFF:129.144.52.38", 80, "/index.html", NULL, NULL } },
        { "http://[2010:836B:4179::836B:4179]";,
          "http://[2010:836B:4179::836B:4179]/";, NULL,
-         { "http", NULL, NULL, "2010:836B:4179::836B:4179", 80, "/", NULL, NULL } },
+         { "http", NULL, NULL, "2010:836B:4179::836B:4179", -1,"/", NULL, NULL } },
 
        /* Try to recover certain kinds of invalid URIs */
        { "http://host/path with spaces",
          "http://host/path%20with%20spaces";, "566530",
-         { "http", NULL, NULL, "host", 80, "/path%20with%20spaces", NULL, NULL } },
-       { "  http://host/path";, "http://host/path";, "594405",
-         { "http", NULL, NULL, "host", 80, "/path", NULL, NULL } },
-       { "http://host/path  ", "http://host/path";, "594405",
-         { "http", NULL, NULL, "host", 80, "/path", NULL, NULL } },
-       { "http://host  ", "http://host/";, "594405",
-         { "http", NULL, NULL, "host", 80, "/", NULL, NULL } },
-       { "http://host:999  ", "http://host:999/";, "594405",
-         { "http", NULL, NULL, "host", 999, "/", NULL, NULL } },
-       { "http://host/pa\nth";, "http://host/path";, "594405",
-         { "http", NULL, NULL, "host", 80, "/path", NULL, NULL } },
-       { "http:\r\n//host/path", "http://host/path";, "594405",
-         { "http", NULL, NULL, "host", 80, "/path", NULL, NULL } },
-       { "http://\thost/path";, "http://host/path";, "594405",
-         { "http", NULL, NULL, "host", 80, "/path", NULL, NULL } },
+         { "http", NULL, NULL, "host", -1,"/path%20with%20spaces", NULL, NULL } },
 
        /* 0-length is different from not-present */
        { "http://host/path?";, "http://host/path?";, "594405",
-         { "http", NULL, NULL, "host", 80, "/path", "", NULL } },
+         { "http", NULL, NULL, "host", -1,"/path", "", NULL } },
        { "http://host/path#";, "http://host/path#";, "594405",
-         { "http", NULL, NULL, "host", 80, "/path", NULL, "" } },
-
-       /* ignore bad %-encoding */
-       { "http://host/path%";, "http://host/path%";, "590524",
-         { "http", NULL, NULL, "host", 80, "/path%", NULL, NULL } },
-       { "http://h%ost/path";, "http://h%25ost/path";, "590524",
-         { "http", NULL, NULL, "h%ost", 80, "/path", NULL, NULL } },
-       { "http://host/path%%";, "http://host/path%%";, "590524",
-         { "http", NULL, NULL, "host", 80, "/path%%", NULL, NULL } },
-       { "http://host/path%%%";, "http://host/path%%%";, "590524",
-         { "http", NULL, NULL, "host", 80, "/path%%%", NULL, NULL } },
-       { "http://host/path%/x/";, "http://host/path%/x/";, "590524",
-         { "http", NULL, NULL, "host", 80, "/path%/x/", NULL, NULL } },
-       { "http://host/path%0x/";, "http://host/path%0x/";, "590524",
-         { "http", NULL, NULL, "host", 80, "/path%0x/", NULL, NULL } },
-       { "http://host/path%ax";, "http://host/path%ax";, "590524",
-         { "http", NULL, NULL, "host", 80, "/path%ax", NULL, NULL } },
+         { "http", NULL, NULL, "host", -1,"/path", NULL, "" } },
 
        /* %-encode non-ASCII characters */
        { "http://host/p\xc3\xa4th/";, "http://host/p%C3%A4th/";, "662806",
-         { "http", NULL, NULL, "host", 80, "/p%C3%A4th/", NULL, NULL } },
+         { "http", NULL, NULL, "host", -1,"/p%C3%A4th/", NULL, NULL } },
 
        { "HTTP:////////////////", "http:////////////////";, "667637",
-         { "http", NULL, NULL, "", 80, "//////////////", NULL, NULL } },
+         { "http", NULL, NULL, "", -1,"//////////////", NULL, NULL } },
 
        { "http://@host";, "http://@host/";, NULL,
-         { "http", "", NULL, "host", 80, "/", NULL, NULL } },
+         { "http", "", NULL, "host", -1,"/", NULL, NULL } },
        { "http://:@host";, "http://@host/";, NULL,
-         { "http", "", "", "host", 80, "/", NULL, NULL } },
+         { "http", "", "", "host", -1,"/", NULL, NULL } },
 
        { "http://host/keep%00nuls";, "http://host/keep%00nuls";, NULL,
-         { "http", NULL, NULL, "host", 80, "/keep%00nuls", NULL, NULL } },
+         { "http", NULL, NULL, "host", -1,"/keep%00nuls", NULL, NULL } },
 
        /* scheme parsing */
        { "foo0://host/path", "foo0://host/path", "703776",
-         { "foo0", NULL, NULL, "host", 0, "/path", NULL, NULL } },
+         { "foo0", NULL, NULL, "host", -1, "/path", NULL, NULL } },
        { "f0.o://host/path", "f0.o://host/path", "703776",
-         { "f0.o", NULL, NULL, "host", 0, "/path", NULL, NULL } },
+         { "f0.o", NULL, NULL, "host", -1, "/path", NULL, NULL } },
        { "http++://host/path", "http++://host/path", "703776",
-         { "http++", NULL, NULL, "host", 0, "/path", NULL, NULL } },
+         { "http++", NULL, NULL, "host", -1, "/path", NULL, NULL } },
        { "http-ish://host/path", "http-ish://host/path", "703776",
-         { "http-ish", NULL, NULL, "host", 0, "/path", NULL, NULL } },
+         { "http-ish", NULL, NULL, "host", -1, "/path", NULL, NULL } },
        { "99http://host/path";, NULL, "703776",
-         { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL } },
+         { NULL, NULL, NULL, NULL, -1, NULL, NULL, NULL } },
        { ".http://host/path";, NULL, "703776",
-         { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL } },
+         { NULL, NULL, NULL, NULL, -1, NULL, NULL, NULL } },
        { "+http://host/path";, NULL, "703776",
-         { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL } },
+         { NULL, NULL, NULL, NULL, -1, NULL, NULL, NULL } },
 
-       /* IPv6 scope ID parsing (both correct and incorrect) */
-       { "http://[fe80::dead:beef%em1]/";, "http://[fe80::dead:beef%25em1]/";, NULL,
-         { "http", NULL, NULL, "fe80::dead:beef%em1", 80, "/", NULL, NULL } },
+       /* IPv6 scope ID parsing */
        { "http://[fe80::dead:beef%25em1]/";, "http://[fe80::dead:beef%25em1]/";, NULL,
-         { "http", NULL, NULL, "fe80::dead:beef%em1", 80, "/", NULL, NULL } },
-       { "http://[fe80::dead:beef%10]/";, "http://[fe80::dead:beef%2510]/";, NULL,
-         { "http", NULL, NULL, "fe80::dead:beef%10", 80, "/", NULL, NULL } },
+         { "http", NULL, NULL, "fe80::dead:beef%em1", -1,"/", NULL, NULL } },
 
        /* ".." past top */
        { "http://example.com/..";, "http://example.com/";, "785042",
-         { "http", NULL, NULL, "example.com", 80, "/", NULL, NULL } },
+         { "http", NULL, NULL, "example.com", -1,"/", NULL, NULL } },
 };
 static int num_abs_tests = G_N_ELEMENTS(abs_tests);
 
+static struct {
+       const char *uri_string, *result, *bugref;
+       const struct UriParts bits;
+} invalid_tests[] = {
+        /* Try to recover certain kinds of invalid URIs */
+       { "  http://host/path";, "http://host/path";, "594405",
+         { "http", NULL, NULL, "host", -1,"/path", NULL, NULL } },
+       { "http://host/path  ", "http://host/path";, "594405",
+         { "http", NULL, NULL, "host", -1,"/path", NULL, NULL } },
+       { "http://host  ", "http://host/";, "594405",
+         { "http", NULL, NULL, "host", -1,"/", NULL, NULL } },
+       { "http://host:999  ", "http://host:999/";, "594405",
+         { "http", NULL, NULL, "host", 999, "/", NULL, NULL } },
+       { "http://host/pa\nth";, "http://host/path";, "594405",
+         { "http", NULL, NULL, "host", -1,"/path", NULL, NULL } },
+       { "http:\r\n//host/path", "http://host/path";, "594405",
+         { "http", NULL, NULL, "host", -1,"/path", NULL, NULL } },
+       { "http://\thost/path";, "http://host/path";, "594405",
+         { "http", NULL, NULL, "host", -1,"/path", NULL, NULL } }, 
+
+       /* ignore bad %-encoding */
+       { "http://h%ost/path";, "http://h%25ost/path";, "590524",
+         { "http", NULL, NULL, "h%ost", -1,"/path", NULL, NULL } }, 
+       { "http://host/path%%";, "http://host/path%%";, "590524",
+         { "http", NULL, NULL, "host", -1,"/path%%", NULL, NULL } },
+       { "http://host/path%%%";, "http://host/path%%%";, "590524",
+         { "http", NULL, NULL, "host", -1,"/path%%%", NULL, NULL } },
+       { "http://host/path%/x/";, "http://host/path%/x/";, "590524",
+         { "http", NULL, NULL, "host", -1,"/path%/x/", NULL, NULL } },
+       { "http://host/path%0x/";, "http://host/path%0x/";, "590524",
+         { "http", NULL, NULL, "host", -1,"/path%0x/", NULL, NULL } },
+       { "http://host/path%ax";, "http://host/path%ax";, "590524",
+         { "http", NULL, NULL, "host", -1,"/path%ax", NULL, NULL } },
+
+       /* IPv6 scope ID parsing (incorrect) */
+        { "http://[fe80::dead:beef%em1]/";, "http://[fe80::dead:beef%25em1]/";, NULL,
+         { "http", NULL, NULL, "fe80::dead:beef%em1", -1,"/", NULL, NULL } },
+       { "http://[fe80::dead:beef%10]/";, "http://[fe80::dead:beef%2510]/";, NULL,
+         { "http", NULL, NULL, "fe80::dead:beef%10", -1,"/", NULL, NULL } },
+};
+static int num_invalid_tests = G_N_ELEMENTS(invalid_tests);
+
+
 /* From RFC 3986. */
 static const char *base = "http://a/b/c/d;p?q";;
 static struct {
        const char *uri_string, *result;
-       const SoupURI bits;
+       const struct UriParts bits;
 } rel_tests[] = {
        { "g:h", "g:h",
-         { "g", NULL, NULL, NULL, 0, "h", NULL, NULL } },
+         { "g", NULL, NULL, NULL, -1, "h", NULL, NULL } },
        { "g", "http://a/b/c/g";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g", NULL, NULL } },
        { "./g", "http://a/b/c/g";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g", NULL, NULL } },
        { "g/", "http://a/b/c/g/";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g/", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g/", NULL, NULL } },
        { "/g", "http://a/g";,
-         { "http", NULL, NULL, "a", 80, "/g", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/g", NULL, NULL } },
        { "//g", "http://g/";,
-         { "http", NULL, NULL, "g", 80, "/", NULL, NULL } },
+         { "http", NULL, NULL, "g", -1,"/", NULL, NULL } },
        { "?y", "http://a/b/c/d;p?y";,
-         { "http", NULL, NULL, "a", 80, "/b/c/d;p", "y", NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/d;p", "y", NULL } },
        { "g?y", "http://a/b/c/g?y";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g", "y", NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g", "y", NULL } },
        { "#s", "http://a/b/c/d;p?q#s";,
-         { "http", NULL, NULL, "a", 80, "/b/c/d;p", "q", "s" } },
+         { "http", NULL, NULL, "a", -1,"/b/c/d;p", "q", "s" } },
        { "g#s", "http://a/b/c/g#s";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g", NULL, "s" } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g", NULL, "s" } },
        { "g?y#s", "http://a/b/c/g?y#s";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g", "y", "s" } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g", "y", "s" } },
        { ";x", "http://a/b/c/;x";,
-         { "http", NULL, NULL, "a", 80, "/b/c/;x", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/;x", NULL, NULL } },
        { "g;x", "http://a/b/c/g;x";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g;x", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g;x", NULL, NULL } },
        { "g;x?y#s", "http://a/b/c/g;x?y#s";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g;x", "y", "s" } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g;x", "y", "s" } },
        { ".", "http://a/b/c/";,
-         { "http", NULL, NULL, "a", 80, "/b/c/", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/", NULL, NULL } },
        { "./", "http://a/b/c/";,
-         { "http", NULL, NULL, "a", 80, "/b/c/", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/", NULL, NULL } },
        { "..", "http://a/b/";,
-         { "http", NULL, NULL, "a", 80, "/b/", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/", NULL, NULL } },
        { "../", "http://a/b/";,
-         { "http", NULL, NULL, "a", 80, "/b/", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/", NULL, NULL } },
        { "../g", "http://a/b/g";,
-         { "http", NULL, NULL, "a", 80, "/b/g", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/g", NULL, NULL } },
        { "../..", "http://a/";,
-         { "http", NULL, NULL, "a", 80, "/", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/", NULL, NULL } },
        { "../../", "http://a/";,
-         { "http", NULL, NULL, "a", 80, "/", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/", NULL, NULL } },
        { "../../g", "http://a/g";,
-         { "http", NULL, NULL, "a", 80, "/g", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/g", NULL, NULL } },
        { "", "http://a/b/c/d;p?q";,
-         { "http", NULL, NULL, "a", 80, "/b/c/d;p", "q", NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/d;p", "q", NULL } },
        { "../../../g", "http://a/g";,
-         { "http", NULL, NULL, "a", 80, "/g", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/g", NULL, NULL } },
        { "../../../../g", "http://a/g";,
-         { "http", NULL, NULL, "a", 80, "/g", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/g", NULL, NULL } },
        { "/./g", "http://a/g";,
-         { "http", NULL, NULL, "a", 80, "/g", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/g", NULL, NULL } },
        { "/../g", "http://a/g";,
-         { "http", NULL, NULL, "a", 80, "/g", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/g", NULL, NULL } },
        { "g.", "http://a/b/c/g.";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g.", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g.", NULL, NULL } },
        { ".g", "http://a/b/c/.g";,
-         { "http", NULL, NULL, "a", 80, "/b/c/.g", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/.g", NULL, NULL } },
        { "g..", "http://a/b/c/g..";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g..", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g..", NULL, NULL } },
        { "..g", "http://a/b/c/..g";,
-         { "http", NULL, NULL, "a", 80, "/b/c/..g", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/..g", NULL, NULL } },
        { "./../g", "http://a/b/g";,
-         { "http", NULL, NULL, "a", 80, "/b/g", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/g", NULL, NULL } },
        { "./g/.", "http://a/b/c/g/";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g/", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g/", NULL, NULL } },
        { "g/./h", "http://a/b/c/g/h";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g/h", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g/h", NULL, NULL } },
        { "g/../h", "http://a/b/c/h";,
-         { "http", NULL, NULL, "a", 80, "/b/c/h", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/h", NULL, NULL } },
        { "g;x=1/./y", "http://a/b/c/g;x=1/y";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g;x=1/y", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g;x=1/y", NULL, NULL } },
        { "g;x=1/../y", "http://a/b/c/y";,
-         { "http", NULL, NULL, "a", 80, "/b/c/y", NULL, NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/y", NULL, NULL } },
        { "g?y/./x", "http://a/b/c/g?y/./x";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g", "y/./x", NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g", "y/./x", NULL } },
        { "g?y/../x", "http://a/b/c/g?y/../x";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g", "y/../x", NULL } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g", "y/../x", NULL } },
        { "g#s/./x", "http://a/b/c/g#s/./x";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g", NULL, "s/./x" } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g", NULL, "s/./x" } },
        { "g#s/../x", "http://a/b/c/g#s/../x";,
-         { "http", NULL, NULL, "a", 80, "/b/c/g", NULL, "s/../x" } },
+         { "http", NULL, NULL, "a", -1,"/b/c/g", NULL, "s/../x" } },
 
        /* RFC 3986 notes that some old parsers will parse this as
         * a relative URL ("http://a/b/c/g";), but it should be
         * interpreted as absolute. libsoup should parse it
-        * correctly as being absolute, but then reject it since it's
-        * an http URL with no host.
+        * correctly as being absolute. Note that SoupURI used to
+        * require a host being non-NULL but GUri accepts it.
         */
-       { "http:g", NULL, { NULL } }
+       { "http:g", "http:g",
+          { "http", NULL, NULL, NULL, -1, "g", NULL, NULL } }
 };
 static int num_rel_tests = G_N_ELEMENTS(rel_tests);
 
@@ -271,41 +292,50 @@ static struct {
 static int num_eq_tests = G_N_ELEMENTS(eq_tests);
 
 static void
-do_uri (SoupURI *base_uri, const char *base_str,
+do_uri (GUri *base_uri, const char *base_str,
        const char *in_uri, const char *out_uri,
-       const SoupURI *bits)
+       const struct UriParts *bits,
+       GUriFlags extra_flags)
 {
-       SoupURI *uri;
+       GUri *uri, *normalized_uri;
        char *uri_string;
+        GError *error = NULL;
 
        if (base_uri) {
                debug_printf (1, "<%s> + <%s> = <%s>\n", base_str, in_uri,
                              out_uri ? out_uri : "ERR");
-               uri = soup_uri_new_with_base (base_uri, in_uri);
+               uri = g_uri_parse_relative (base_uri, in_uri, SOUP_HTTP_URI_FLAGS | extra_flags, &error);
        } else {
                debug_printf (1, "<%s> => <%s>\n", in_uri,
                              out_uri ? out_uri : "ERR");
-               uri = soup_uri_new (in_uri);
+                uri = g_uri_parse (in_uri, SOUP_HTTP_URI_FLAGS | extra_flags, &error);
        }
 
-       if (!uri) {
-               g_assert_null (out_uri);
-               return;
-       }
+        if (!out_uri) {
+                g_assert_null (uri);
+                return;
+        }
+
+        g_assert_no_error (error);
+        g_assert_nonnull (uri);
+
+        normalized_uri = soup_normalize_uri (uri);
+        g_uri_unref (uri);
+        uri = normalized_uri;
 
        if (bits != NULL) {
-               g_assert_cmpstr (uri->scheme, ==, bits->scheme);
-               g_assert_cmpstr (uri->user, ==, bits->user);
-               g_assert_cmpstr (uri->password, ==, bits->password);
-               g_assert_cmpstr (uri->host, ==, bits->host);
-               g_assert_cmpuint (uri->port, ==, bits->port);
-               g_assert_cmpstr (uri->path, ==, bits->path);
-               g_assert_cmpstr (uri->query, ==, bits->query);
-               g_assert_cmpstr (uri->fragment, ==, bits->fragment);
+               g_assert_cmpstr (g_uri_get_scheme (uri), ==, bits->scheme);
+               g_assert_cmpstr (g_uri_get_user (uri), ==, bits->user);
+               g_assert_cmpstr (g_uri_get_password (uri), ==, bits->password);
+               g_assert_cmpstr (g_uri_get_host (uri), ==, bits->host);
+               g_assert_cmpint (g_uri_get_port (uri), ==, bits->port);
+               g_assert_cmpstr (g_uri_get_path (uri), ==, bits->path);
+               g_assert_cmpstr (g_uri_get_query (uri), ==, bits->query);
+               g_assert_cmpstr (g_uri_get_fragment (uri), ==, bits->fragment);
        }
 
-       uri_string = soup_uri_to_string (uri, FALSE);
-       soup_uri_free (uri);
+       uri_string = g_uri_to_string_partial (uri, G_URI_HIDE_PASSWORD);
+       g_uri_unref (uri);
 
        g_assert_cmpstr (uri_string, ==, out_uri);
        g_free (uri_string);
@@ -320,142 +350,73 @@ do_absolute_uri_tests (void)
                if (abs_tests[i].bugref)
                        g_test_bug (abs_tests[i].bugref);
                do_uri (NULL, NULL, abs_tests[i].uri_string,
-                       abs_tests[i].result, &abs_tests[i].bits);
+                       abs_tests[i].result, &abs_tests[i].bits,
+                        0);
+       }
+}
+
+static void
+do_invalid_uri_tests (void)
+{
+       for (int i = 0; i < num_invalid_tests; i++) {
+               if (invalid_tests[i].bugref)
+                       g_test_bug (invalid_tests[i].bugref);
+               do_uri (NULL, NULL, invalid_tests[i].uri_string,
+                       invalid_tests[i].result, &invalid_tests[i].bits,
+                        G_URI_FLAGS_PARSE_RELAXED);
        }
 }
 
 static void
 do_relative_uri_tests (void)
 {
-       SoupURI *base_uri;
+       GUri *base_uri;
        char *uri_string;
        int i;
 
-       base_uri = soup_uri_new (base);
+       base_uri = g_uri_parse (base, SOUP_HTTP_URI_FLAGS, NULL);
        if (!base_uri) {
                g_printerr ("Could not parse %s!\n", base);
                exit (1);
        }
 
-       uri_string = soup_uri_to_string (base_uri, FALSE);
+       uri_string = g_uri_to_string (base_uri);
        g_assert_cmpstr (uri_string, ==, base);
        g_free (uri_string);
 
        for (i = 0; i < num_rel_tests; i++) {
                do_uri (base_uri, base, rel_tests[i].uri_string,
-                       rel_tests[i].result, &rel_tests[i].bits);
+                       rel_tests[i].result, &rel_tests[i].bits,
+                        0);
        }
-       soup_uri_free (base_uri);
+       g_uri_unref (base_uri);
 }
 
 static void
 do_equality_tests (void)
 {
-       SoupURI *uri1, *uri2;
+       GUri *uri1, *uri2, *norm1, *norm2;
        int i;
 
        for (i = 0; i < num_eq_tests; i++) {
                if (eq_tests[i].bugref)
                        g_test_bug (eq_tests[i].bugref);
 
-               uri1 = soup_uri_new (eq_tests[i].one);
-               uri2 = soup_uri_new (eq_tests[i].two);
+               uri1 = g_uri_parse (eq_tests[i].one, SOUP_HTTP_URI_FLAGS, NULL);
+               uri2 = g_uri_parse (eq_tests[i].two, SOUP_HTTP_URI_FLAGS, NULL);
+                norm1 = soup_normalize_uri (uri1);
+                norm2 = soup_normalize_uri (uri2);
 
                debug_printf (1, "<%s> == <%s>\n", eq_tests[i].one, eq_tests[i].two);
-               g_assert_true (soup_uri_equal (uri1, uri2));
+               g_assert_true (soup_uri_equal (norm1, norm2));
 
-               soup_uri_free (uri1);
-               soup_uri_free (uri2);
+               g_uri_unref (uri1);
+               g_uri_unref (uri2);
+                g_uri_unref (norm1);
+                g_uri_unref (norm2);
        }
 }
 
-static void
-do_soup_uri_null_tests (void)
-{
-       SoupURI *uri, *uri2;
-       char *uri_string;
-
-       g_test_bug ("667637");
-       g_test_bug ("670431");
-
-       uri = soup_uri_new (NULL);
-       g_assert_false (SOUP_URI_IS_VALID (uri));
-       g_assert_false (SOUP_URI_VALID_FOR_HTTP (uri));
-
-       /* This implicitly also verifies that none of these methods g_warn */
-       g_assert_null (soup_uri_get_scheme (uri));
-       g_assert_null (soup_uri_get_user (uri));
-       g_assert_null (soup_uri_get_password (uri));
-       g_assert_null (soup_uri_get_host (uri));
-       g_assert_cmpint (soup_uri_get_port (uri), ==, 0);
-       g_assert_null (soup_uri_get_path (uri));
-       g_assert_null (soup_uri_get_query (uri));
-       g_assert_null (soup_uri_get_fragment (uri));
-
-       g_test_expect_message ("libsoup", G_LOG_LEVEL_CRITICAL,
-                              "*base == NULL*");
-       uri2 = soup_uri_new_with_base (uri, "/path");
-       g_test_assert_expected_messages ();
-       g_assert_null (uri2);
-
-       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
-                              "*SOUP_URI_IS_VALID*");
-       uri_string = soup_uri_to_string (uri, FALSE);
-       g_test_assert_expected_messages ();
-       g_assert_cmpstr (uri_string, ==, "");
-       g_free (uri_string);
-
-       soup_uri_set_scheme (uri, SOUP_URI_SCHEME_HTTP);
-       g_assert_false (SOUP_URI_IS_VALID (uri));
-       g_assert_false (SOUP_URI_VALID_FOR_HTTP (uri));
-
-       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
-                              "*SOUP_URI_IS_VALID*");
-       uri_string = soup_uri_to_string (uri, FALSE);
-       g_test_assert_expected_messages ();
-       g_assert_cmpstr (uri_string, ==, "http:");
-       g_free (uri_string);
-
-       soup_uri_set_host (uri, "localhost");
-       g_assert_false (SOUP_URI_IS_VALID (uri));
-       g_assert_false (SOUP_URI_VALID_FOR_HTTP (uri));
-
-       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
-                              "*SOUP_URI_IS_VALID*");
-       uri_string = soup_uri_to_string (uri, FALSE);
-       g_test_assert_expected_messages ();
-       g_assert_cmpstr (uri_string, ==, "http://localhost/";);
-       g_free (uri_string);
-
-       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
-                              "*SOUP_URI_IS_VALID*");
-       uri2 = soup_uri_new_with_base (uri, "/path");
-       g_test_assert_expected_messages ();
-       g_assert_true (uri2 != NULL);
-
-       if (uri2) {
-               uri_string = soup_uri_to_string (uri2, FALSE);
-               g_assert_cmpstr (uri_string, ==, "http://localhost/path";);
-               g_free (uri_string);
-               soup_uri_free (uri2);
-       }
-
-       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
-                              "*path != NULL*");
-       soup_uri_set_path (uri, NULL);
-       g_test_assert_expected_messages ();
-       g_assert_cmpstr (uri->path, ==, "");
-
-       uri_string = soup_uri_to_string (uri, FALSE);
-       g_assert_cmpstr (uri_string, ==, "http://localhost/";);
-       g_free (uri_string);
-
-       g_assert_true (SOUP_URI_IS_VALID (uri));
-       g_assert_true (SOUP_URI_VALID_FOR_HTTP (uri));
-
-       soup_uri_free (uri);
-}
-
 static struct {
        const char *uri_string, *unescape_extra, *result;
 } normalization_tests[] = {
@@ -564,14 +525,6 @@ do_data_tests (void)
        soup_test_session_abort_unref (session);
 }
 
-static void
-test_uri_decode (void)
-{
-       gchar *decoded = soup_uri_decode ("%");
-       g_assert_cmpstr (decoded, ==, "%");
-       g_free (decoded);
-}
-
 int
 main (int argc, char **argv)
 {
@@ -580,12 +533,11 @@ main (int argc, char **argv)
        test_init (argc, argv, NULL);
 
        g_test_add_func ("/uri/absolute", do_absolute_uri_tests);
+        g_test_add_func ("/uri/invalid", do_invalid_uri_tests);
        g_test_add_func ("/uri/relative", do_relative_uri_tests);
        g_test_add_func ("/uri/equality", do_equality_tests);
-       g_test_add_func ("/uri/null", do_soup_uri_null_tests);
        g_test_add_func ("/uri/normalization", do_normalization_tests);
        g_test_add_func ("/uri/data", do_data_tests);
-       g_test_add_func ("/uri/decode", test_uri_decode);
 
        ret = g_test_run ();
 
diff --git a/tests/websocket-test.c b/tests/websocket-test.c
index 5e40cf36..bc55f8bb 100644
--- a/tests/websocket-test.c
+++ b/tests/websocket-test.c
@@ -105,7 +105,7 @@ direct_connection_complete (GObject *object,
 {
        Test *test = user_data;
        GSocketConnection *conn;
-       SoupURI *uri;
+       GUri *uri;
        GError *error = NULL;
        GList *extensions = NULL;
 
@@ -113,7 +113,7 @@ direct_connection_complete (GObject *object,
                                                       result, &error);
        g_assert_no_error (error);
 
-       uri = soup_uri_new ("http://127.0.0.1/";);
+       uri = g_uri_parse ("http://127.0.0.1/";, SOUP_HTTP_URI_FLAGS, NULL);
        if (test->enable_extensions) {
                SoupWebsocketExtension *extension;
 
@@ -127,7 +127,7 @@ direct_connection_complete (GObject *object,
                                                                      SOUP_WEBSOCKET_CONNECTION_CLIENT,
                                                                      NULL, NULL,
                                                                      extensions);
-       soup_uri_free (uri);
+       g_uri_unref (uri);
        g_object_unref (conn);
 }
 
@@ -139,7 +139,7 @@ got_connection (GSocket *listener,
        Test *test = user_data;
        GSocket *sock;
        GSocketConnection *conn;
-       SoupURI *uri;
+       GUri *uri;
        GList *extensions = NULL;
        GError *error = NULL;
 
@@ -153,7 +153,7 @@ got_connection (GSocket *listener,
        if (test->no_server)
                test->raw_server = G_IO_STREAM (conn);
        else {
-               uri = soup_uri_new ("http://127.0.0.1/";);
+               uri = g_uri_parse ("http://127.0.0.1/";, SOUP_HTTP_URI_FLAGS, NULL);
                if (test->enable_extensions) {
                        SoupWebsocketExtension *extension;
 
@@ -167,7 +167,7 @@ got_connection (GSocket *listener,
                                                                              
SOUP_WEBSOCKET_CONNECTION_SERVER,
                                                                              NULL, NULL,
                                                                              extensions);
-               soup_uri_free (uri);
+               g_uri_unref (uri);
                g_object_unref (conn);
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]