Fix failure to respect default port of proxy URLs

Currently we require explicitly specifying the port when configuring a
proxy server, which is seriously weird. I take the fact that nobody
reported a bug until 2022 to indicate that almost nobody is using
proxies. Whatever. Let's assume that if no port is provided, the default
port for the protocol should be used instead.

For example, you can now specify in GNOME settings that your proxy server
is https://example.com and it will work. Previously, you had to write
https://example.com:443. Yuck!

This was originally reported as GProxyResolver bug, but nothing is
actually wrong there. It's actually GProxyAddressEnumerator that gets
tripped up by URLs returned by GProxyResolver without a default port.
This breaks GSocketClient.

Fixing this requires exposing GUri's _default_scheme_port() function to
GIO. I considered copy/pasting it since it's not very much code, but I
figure the private call mechanism is probably not too expensive, and I
don't like code duplication.

Fixes #2832
This commit is contained in:
Michael Catanzaro
2023-05-24 17:37:57 -05:00
parent 42cb8dfb95
commit cc5bb80b9a
4 changed files with 18 additions and 5 deletions

View File

@@ -29,6 +29,7 @@
#include "ginetaddress.h"
#include "gioerror.h"
#include "glibintl.h"
#include "glib-private.h"
#include "gnetworkaddress.h"
#include "gnetworkingprivate.h"
#include "gproxy.h"
@@ -158,9 +159,13 @@ next_enumerator (GProxyAddressEnumeratorPrivate *priv)
else
{
GError *error = NULL;
int default_port;
connectable = g_network_address_parse_uri (priv->proxy_uri, 0, &error);
default_port = GLIB_PRIVATE_CALL (g_uri_get_default_scheme_port) (priv->proxy_type);
if (default_port == -1)
default_port = 0;
connectable = g_network_address_parse_uri (priv->proxy_uri, default_port, &error);
if (error)
{
g_warning ("Invalid proxy URI '%s': %s",