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

Check NO_PROXY env to disable proxy settings #11497

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions news/5378.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check ``NO_PROXY`` env variable to disable proxy settings.
4 changes: 3 additions & 1 deletion src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ def _build_session(
session.timeout = timeout if timeout is not None else options.timeout

# Handle configured proxies
if options.proxy:
if "no_proxy" in os.environ or "NO_PROXY" in os.environ:
session.proxies["no_proxy"] = "*"
elif options.proxy:
session.proxies = {
"http": options.proxy,
"https": options.proxy,
Expand Down
34 changes: 34 additions & 0 deletions tests/functional/test_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from pathlib import Path
from typing import Any, Dict

import proxy
import pytest
from proxy.http.proxy import HttpProxyBasePlugin

from tests.lib import PipTestEnvironment


class AccessLogPlugin(HttpProxyBasePlugin):
def on_access_log(self, context: Dict[str, Any]) -> None:
print(context)


@pytest.mark.network
def test_no_proxy(
script: PipTestEnvironment, capfd: pytest.CaptureFixture[str]
) -> None:
with proxy.Proxy(port=8888, num_acceptors=1, plugins=[AccessLogPlugin]):
script.environ["no_proxy"] = "1"
result = script.pip(
"download",
"--proxy",
"http://127.0.0.1:8888",
"--trusted-host",
"127.0.0.1",
"-d",
"pip_downloads",
"INITools==0.1",
)
result.did_create(Path("scratch") / "pip_downloads" / "INITools-0.1.tar.gz")
out, _ = capfd.readouterr()
assert "CONNECT" not in out
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ virtualenv < 20.0
werkzeug
wheel
tomli-w
proxy.py