Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically fallback to DIRECT when PAC unavailable #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SamuelePilleri
Copy link

When the configured PAC file is unavailable Windows automatically reverts to DIRECT connections, which is useful for example when connecting the work laptop to home Wi-Fi.
This commit mimics said behaviour.

When the configured PAC file is unavailable Windows automatically reverts to DIRECT connections, which is useful for example when connecting the work laptop to home Wi-Fi.
This commit mimics said behaviour.
@genotrance
Copy link
Owner

Thanks for the PR.

This change reverts to DIRECT if the PAC javascript parsing fails for some reason, but it could fail for other reasons. If PAC file doesn't exist or URL fails connect or load in pac.py (e.g. see #167), exception will be raised and not caught for first connection.

px/px/pac.py

Lines 40 to 53 in faaa57c

def load_jsfile(self, jsfile):
"Load specified JS file into this context"
dprint("Loading PAC file: " + jsfile)
with open(jsfile) as js:
self.ctxt.eval(js.read())
def load_url(self, jsurl):
dprint("Loading PAC url: " + jsurl)
c = Curl(jsurl)
c.set_debug()
c.buffer()
c.set_follow()
if c.perform():
self.ctxt.eval(c.get_data())

wproxy.py code below does not handle failures for the first time and subsequent calls will have self.pac != None. This will be handled by your change but could be cleaner. Maybe not set self.pac if loading failed.

px/px/wproxy.py

Lines 247 to 256 in faaa57c

if self.pac is None:
# Load PAC file
self.pac = Pac(debug_print = dprint)
if self.servers[0].startswith("http"):
self.pac.load_url(self.servers[0])
else:
self.pac.load_jsfile(self.servers[0])
if self.pac is not None:
return parse_proxy(self.pac.find_proxy_for_url(url, netloc[0])), netloc, path

Might be more cases but this is what stands out right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants