samuong / alpaca

A local HTTP proxy for command-line tools. Supports PAC scripts and NTLM authentication.
Apache License 2.0
202 stars 35 forks source link

Alpaca doesn't detect when the system's PAC URL changes #91

Open samuong opened 2 years ago

samuong commented 2 years ago

Currently, the PAC URL is read from the system settings before downloading the PAC file. This is done by calling out to a subprocess (gsettings or networksetup on Linux and macOS - but for Windows this is not yet implemented) and reading stdout. It takes around 50-60ms on my M1 MacBook Pro, which is too slow to do on every outgoing request. But if we don't check this value frequently, the configured PAC URL can change and Alpaca won't notice.

We can make the findPACURL() function faster by calling the native system libraries from Cgo. This will then allow us to check the PAC URL before Alpaca forwards each outgoing request.

Linux (GNOME)

https://wiki.gnome.org/DevGnomeOrg/Gnome3PortingGuide/ProxyConfiguration https://docs.gtk.org/gio/class.Settings.html

macOS

https://developer.apple.com/documentation/systemconfiguration/1517088-scdynamicstorecopyproxies

Windows

https://docs.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpgetieproxyconfigforcurrentuser

christogav commented 2 years ago

Suggested fix at #103.