Skip to content

bpo-29533 Added option smart_proxy_bypass in request module #247

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions Lib/urllib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2674,6 +2674,9 @@ def getproxies():
"""
return getproxies_environment() or getproxies_registry()

# Undocumented feature: set this to True to check if IP and FQDN of the host
# match one of the registry values.
smart_proxy_bypass = False
def proxy_bypass_registry(host):
try:
import winreg
Expand All @@ -2692,21 +2695,22 @@ def proxy_bypass_registry(host):
return 0
if not proxyEnable or not proxyOverride:
return 0
# try to make a host list from name and IP address.
rawHost, port = splitport(host)
host = [rawHost]
try:
addr = socket.gethostbyname(rawHost)
if addr != rawHost:
host.append(addr)
except OSError:
pass
try:
fqdn = socket.getfqdn(rawHost)
if fqdn != rawHost:
host.append(fqdn)
except OSError:
pass
if smart_proxy_bypass:
# try to add IP and FQDN to the host list.
try:
addr = socket.gethostbyname(rawHost)
if addr != rawHost:
host.append(addr)
except OSError:
pass
try:
fqdn = socket.getfqdn(rawHost)
if fqdn != rawHost:
host.append(fqdn)
except OSError:
pass
# make a check value list from the registry entry: replace the
# '<local>' string by the localhost entry and the corresponding
# canonical entry.
Expand Down