Skip to content

Commit

Permalink
Merge pull request #488 from rstudio/no-proxy
Browse files Browse the repository at this point in the history
Add NO_PROXY support
  • Loading branch information
mmarchetti authored Oct 5, 2023
2 parents 8774dc6 + 2b8dc59 commit f4def0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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", "#"))
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

0 comments on commit f4def0c

Please sign in to comment.