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

Add NO_PROXY support #488

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased

### Fixed
- The `https_proxy` environment variable is recognized as a synonym for
`HTTPS_PROXY`.

### Added
- Added support for the `no_proxy` or `NO_PROXY` environment variables to specify
hosts that should not be accessed via proxy server. It's a comma-separated list
of host or domain suffixes. For example, specifying `example.com` will
bypass the proxy for example.com, host.example.com, etc.

## [1.20.0] - 2023-09-11

Expand Down
9 changes: 7 additions & 2 deletions rsconnect/http_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _create_plain_connection(host_name, port, disable_tls_check, ca_data):


def _get_proxy():
proxyURL = os.getenv("HTTPS_PROXY")
proxyURL = os.getenv("https_proxy", os.getenv("HTTPS_PROXY"))
if not proxyURL:
return None, None, None, None
parsed = urlparse(proxyURL)
Expand Down Expand Up @@ -75,7 +75,12 @@ def _create_ssl_connection(host_name, port, disable_tls_check, ca_data):
"""
if ca_data is not None and disable_tls_check:
raise ValueError("Cannot both disable TLS checking and provide a custom certificate")
_, _, proxyHost, proxyPort = _get_proxy()

no_proxy = os.environ.get("no_proxy", os.environ.get("NO_PROXY", "#"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the default value '#'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't ever match a hostname. Since the check is endswith, an empty string would be interpreted as matching all hosts.

if any([host_name.endswith(host) for host in no_proxy.split(",")]):
proxyHost, proxyPort = None, None
else:
_, _, proxyHost, proxyPort = _get_proxy()
headers = _get_proxy_headers()
timeout = get_request_timeout()
logger.debug(f"The HTTPSConnection timeout is set to '{timeout}' seconds")
Expand Down
Loading