diff options
author | Patrick Griffis <pgriffis@igalia.com> | 2020-07-27 18:07:37 +0400 |
---|---|---|
committer | Patrick Griffis <tingping@tingping.se> | 2020-11-14 19:07:24 +0000 |
commit | 737eef099ca1e34d18245c54b6ed3ba54faf1f9c (patch) | |
tree | 9e35180cd68cefa2f515f7b38c28fc2000d7cf37 /libsoup/hsts | |
parent | 0f471888b8ad4ab97283023109bcbde714f2ed48 (diff) | |
download | libsoup-737eef099ca1e34d18245c54b6ed3ba54faf1f9c.tar.gz |
Replace SoupURI with GUri
Diffstat (limited to 'libsoup/hsts')
-rw-r--r-- | libsoup/hsts/soup-hsts-enforcer.c | 49 | ||||
-rw-r--r-- | libsoup/hsts/soup-hsts-enforcer.h | 2 | ||||
-rw-r--r-- | libsoup/hsts/soup-hsts-policy.c | 4 |
3 files changed, 34 insertions, 21 deletions
diff --git a/libsoup/hsts/soup-hsts-enforcer.c b/libsoup/hsts/soup-hsts-enforcer.c index 9e024de9..8925f5ac 100644 --- a/libsoup/hsts/soup-hsts-enforcer.c +++ b/libsoup/hsts/soup-hsts-enforcer.c @@ -466,7 +466,7 @@ soup_hsts_enforcer_process_sts_header (SoupHSTSEnforcer *hsts_enforcer, SoupMessage *msg) { SoupHSTSPolicy *policy; - SoupURI *uri; + GUri *uri; uri = soup_message_get_uri (msg); @@ -487,24 +487,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 @@ -525,19 +540,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) @@ -551,7 +564,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 1010a4ce..adba626f 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 f17eebbe..e78d7fda 100644 --- a/libsoup/hsts/soup-hsts-policy.c +++ b/libsoup/hsts/soup-hsts-policy.c @@ -274,7 +274,7 @@ soup_hsts_policy_new_from_response (SoupMessage *msg) soup_message_headers_iter_init (&iter, soup_message_get_response_headers (msg)); while (soup_message_headers_iter_next (&iter, &name, &value)) { - SoupURI *uri; + GUri *uri; GHashTable *params; const char *max_age_str; char *endptr; @@ -307,7 +307,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; |