Bug 228233

Summary: [GTK] Allow to set GProxyResolver directly
Product: WebKit Reporter: Milan Crha <mcrha>
Component: WebKitGTKAssignee: Nobody <webkit-unassigned>
Status: RESOLVED WONTFIX    
Severity: Normal CC: bugs-noreply, cgarcia, mcatanzaro
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Description Milan Crha 2021-07-23 04:41:14 PDT
The WebKitNetworkProxySettings lets me set only some values, which I'd extract from a GProxyResolver object, just to turn it back into a new GProxyResolver object, which is unnecessary, when I already have the proxy resolver ready.

Could you make the WebKitNetworkProxySettings accept also the GProxyResolver, instead of the extracted data, please?

I guess it can work to add a new WEBKIT_NETWORK_PROXY_MODE_RESOLVER and the counterparts, webkit_network_proxy_settings_set/get_resolver(), thus the API of the webkit_website_data_manager_set_network_proxy_settings() won't change.
Comment 1 Milan Crha 2021-07-23 04:50:16 PDT
A function like `webkit_network_proxy_settings_new_with_resolver` would be also nice to have.
Comment 2 Carlos Garcia Campos 2021-07-23 05:00:11 PDT
The proxy resolver is not used in the UI process, but the network process. What we want is the proxy configuration, to be sent to the network process.
Comment 3 Milan Crha 2021-07-23 05:33:15 PDT
How do I know what to use, when I do not know where the page can redirect, or from where it can get its resources? The GProxyResolver has the lookup function, which returns what proxies (a plural) should be used for the given URL.
Comment 4 Michael Catanzaro 2021-07-23 07:51:14 PDT
(In reply to Milan Crha from comment #3)
> How do I know what to use, when I do not know where the page can redirect,
> or from where it can get its resources? The GProxyResolver has the lookup
> function, which returns what proxies (a plural) should be used for the given
> URL.

Um... the WebKit network proxy settings are for input only. If you want to know which proxy to use for a network request, you should use your own GProxyResolver. Right?

Of course it's impossible to pass a GProxyResolver to the network process, because there's no way it could be serialized.
Comment 5 Milan Crha 2021-07-26 07:23:22 PDT
(In reply to Michael Catanzaro from comment #4)
> Um... the WebKit network proxy settings are for input only. If you want to
> know which proxy to use for a network request, you should use your own
> GProxyResolver. Right?

That's my point, yes.

> Of course it's impossible to pass a GProxyResolver to the network process,
> because there's no way it could be serialized.

Understood. It (the current design?) makes things impossible to do, it seems.
Comment 6 Michael Catanzaro 2021-07-26 08:46:52 PDT
The only possible way to add such APIs to WebKit would be to first add g_proxy_resolver_serialize() and g_proxy_resolver_deserialize() APIs to GProxyResolver and have every existing GProxyResolver implement it. Maybe it's not impossible, but this would be complicated to do. Is there some serious concrete benefit to this, given that the default GProxyResolver which uses OS proxy settings should be sufficient unless your application offers custom proxy settings? Are the existing WebKitProxySettings APIs somehow insufficient to implement your custom proxy settings?

So Milan: can I close this bug? Or do you really have a use-case that requires adding g_proxy_resolver_serialize() and g_proxy_resolver_deserialize()?
Comment 7 Milan Crha 2021-07-27 00:18:25 PDT
> unless your application offers custom proxy settings?

Right, my application (Evolution) offers its own proxy settings.

> Or do you really have a use-case...

I do not know. I guess you can close this. I did not know (did not realize until it had been mentioned here) the settings go to the network process.

I also do not know how the g_proxy_resolver_lookup() works in the background. If it can return different results for different http://|https:// requests, then it's impossible to convert into WebKit's proxy settings. The g_proxy_resolver_lookup() also returns an array of the proxy server URIs, but the webkit_network_proxy_settings_add_proxy_for_scheme() seems to allow only a single proxy URI to be added for the scheme.

As you can see, many things are due to my lack of knowledge. The Evolution's settings are not that complicated as the GProxyResolver API allows, thus I might be able to make this work with the current WebKit implementation.
Comment 8 Milan Crha 2021-07-27 03:43:53 PDT
I forgot to close this. I'm sorry for the noise.
Comment 9 Michael Catanzaro 2021-07-27 04:40:48 PDT
(In reply to Milan Crha from comment #7)
> I also do not know how the g_proxy_resolver_lookup() works in the
> background. If it can return different results for different
> http://|https:// requests, then it's impossible to convert into WebKit's
> proxy settings. 

Correct, it is impossible to convert an arbitrary GProxyResolver into WebKitNetworkProxySettings, because GProxyResolver can (and will!) return different results for different requests. E.g. a common configuration would be to use a special proxy only for a specific list of domains, and connect directly to everything else. This cannot be expressed with WebKitNetworkProxySettings (it's just a wrapper around GSimpleProxyResolver) and so that limits what you can do with your application's proxy configuration dialog relative to what an app that doesn't use WebKit can do. But the more complex configuration will still be supported just fine if configured using system settings, and in practice that's probably sufficient I think, especially given that almost nobody uses proxies anymore anyway.

> The g_proxy_resolver_lookup() also returns an array of the
> proxy server URIs, but the
> webkit_network_proxy_settings_add_proxy_for_scheme() seems to allow only a
> single proxy URI to be added for the scheme.

Right.

> As you can see, many things are due to my lack of knowledge. The Evolution's
> settings are not that complicated as the GProxyResolver API allows, thus I
> might be able to make this work with the current WebKit implementation.

Hopefully!
Comment 10 Milan Crha 2021-07-27 04:51:25 PDT
(In reply to Michael Catanzaro from comment #9)
> > As you can see, many things are due to my lack of knowledge. The Evolution's
> > settings are not that complicated as the GProxyResolver API allows, thus I
> > might be able to make this work with the current WebKit implementation.
> 
> Hopefully!

I realized it's relatively simple to do, except of an autoconfig URL, which queries PACRunner to get the proxy for a given URL. The setting itself provides only the autoconfig URL and nothing else.

Maybe you can add an option for this into the WebKit proxy settings? Getting the result is as simple as a D-Bus call:
https://gitlab.gnome.org/GNOME/evolution-data-server/-/blob/master/src/libedataserver/e-source-proxy.c#L155

I'm not insisting on this, my eds patch currently says "not supported by WebKit".
Comment 11 Michael Catanzaro 2021-07-27 05:15:07 PDT
Unfortunately that's precisely what I was hoping you *wouldn't* have in your UI.

GSimpleProxyResolver doesn't support PAC. We'd need to either (a) add g_proxy_resolver_serialize() and g_proxy_resolver_deserialize() and let you set your own GProxyResolver, or (b) copy over a more complex GProxyResolver that does support PAC from glib-networking, or (c) maybe we can directly instantiate one of glib-networking's GProxyResolvers only if its type is registered?, or (d) write our own simple one that just handles PAC using that glib-pacrunner D-Bus API.

(Note that glib-pacrunner is currently either missing or broken in RHEL 9. I need to rewrite it to not depend on libproxy.)
Comment 12 Michael Catanzaro 2021-07-27 05:36:50 PDT
(In reply to Milan Crha from comment #10)
> I'm not insisting on this, my eds patch currently says "not supported by
> WebKit".

The other thing you could do is instruct the user to configure PAC using system proxy settings instead, if available.