Skip to content

feature: Add support for HTTP_PROXY, HTTPS_PROXY, and NO_PROXY#1260

Open
peterguy wants to merge 47 commits intomainfrom
peterguy/support-http_proxy
Open

feature: Add support for HTTP_PROXY, HTTPS_PROXY, and NO_PROXY#1260
peterguy wants to merge 47 commits intomainfrom
peterguy/support-http_proxy

Conversation

@peterguy
Copy link
Copy Markdown
Contributor

@peterguy peterguy commented Feb 25, 2026

Adds support for the standard environment variables HTTP_PROXY, HTTPS_PROXY, and NO_PROXY.

SRC_PROXY still takes precedence, including over NO_PROXY.

Test plan

Added CI tests validating proxy connection behavior.

Manual testing

Install mitmproxy, socat and squid (brew install mitmproxy socat squid for me).

Create an SSL cert for squid:

openssl req -x509 -newkey rsa:2048 \
  -keyout ${HOME}/squid-key.pem -out ${HOME}/squid-cert.pem \
  -days 365 -nodes -subj "/CN=localhost"
cat ${HOME}/squid-key.pem ${HOME}/squid-cert.pem > ${HOME}/squid-proxy.pem

Create a config for squid:

cat << EOF >${HOME}/squid.conf
https_port 8445 cert=${HOME}/squid-proxy.pem
sslproxy_session_cache_size 0
acl localnet src 127.0.0.1/32
http_access allow localhost
acl SSL_ports port 443
acl Safe_ports port 80
acl Safe_ports port 443
acl Safe_ports port 1025-65535
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny all
http_port 3128
EOF

Launch three terminals to run the proxies:

  • run socat -d -d unix-listen:${HOME}/src-proxy.sock,fork tcp:localhost:8080 in one.
  • run mitmproxy -v in another.
  • run squid - squid -f ${HOME}/squid.conf -N -d 1 - in the third.

In a fourth terminal, in the src-cli repo, build the binary: go build -o ./src-cli ./cmd/src

Ensure you have SRC_ENDPOINT and SRC_ACCESS_TOKEN set in your environment, and unset SRC_PROXY. SRC_ENDPOINT needs to be https://.

Connect with each proxy (mitmproxy is 8080, squid is 8445) and with no proxy:

for x in http://localhost:8080 http://localhost:3128 https://localhost:8445
do
HTTPS_PROXY=${x} ./src-cli login --insecure-skip-verify=true
SRC_PROXY=${x} ./src-cli login --insecure-skip-verify=true
HTTPS_PROXY=${x} NO_PROXY=${${SRC_ENDPOINT#*://}%%/*} ./src-cli login --insecure-skip-verify=true
SRC_PROXY=${x} NO_PROXY=${${SRC_ENDPOINT#*://}%%/*} ./src-cli login --insecure-skip-verify=true
done
HTTPS_PROXY="" SRC_PROXY="" ./src-cli login --insecure-skip-verify=true
SRC_PROXY=${HOME}/src-proxy.sock ./src-cli login --insecure-skip-verify=true

You should get 14 "Authenticated as [USER] on [ENDPOINT]" messages in your terminal. You should see four connections in mitmproxy, six in squid, and several lines in socat indicating one connection.

This test ensures:

  • all of the proxy environment variables are supported (SRC_PROXY, HTTPS_PROXY, NO_PROXY)
  • NO_PROXY trumps HTTPS_PROXY
  • SRC_PROXY trumps HTTPS_PROXY and NO_PROXY
  • both plain HTTP and TLS-enabled proxies are supported
  • the ability to connect to UNIX Domain Sockets is preserved
  • communication with no proxy at all is successful

Cleanup from the test:

  • terminate all running proxy processes.
  • rm -f ${HOME}/squid-proxy.pem ${HOME}/squid-key.pem ${HOME}/squid-cert.pem ${HOME}/squid.conf ${HOME}/src-proxy.sock

Closes https://linear.app/sourcegraph/issue/CPL-236/src-cli-support-standard-http-proxy

@keegancsmith keegancsmith requested a review from a team February 26, 2026 07:12
Copy link
Copy Markdown
Member

@keegancsmith keegancsmith left a comment

Choose a reason for hiding this comment

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

Nice! Inline comments, but otherwise LGTM

@keegancsmith
Copy link
Copy Markdown
Member

You might wanna rebase, I think william just did some CI updates which include things like go-lint/etc.

@peterguy
Copy link
Copy Markdown
Contributor Author

Thanks for all of your commentary; I forgot to open this PR in draft mode! Been trying to address what looks like flakey tests in the Ubuntu CI runner; I'll go through your very helpful comments soon.

@peterguy
Copy link
Copy Markdown
Contributor Author

peterguy commented Feb 27, 2026

@peterguy peterguy force-pushed the peterguy/support-http_proxy branch from b1d6176 to 05f0fbb Compare February 27, 2026 00:48
@keegancsmith
Copy link
Copy Markdown
Member

@peterguy alright just re-request review when ready.

@peterguy peterguy force-pushed the peterguy/support-http_proxy branch from 622bd60 to 3536377 Compare February 27, 2026 19:40
Copy link
Copy Markdown
Member

@keegancsmith keegancsmith left a comment

Choose a reason for hiding this comment

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

Requesting changes since I just wanna re-review once you have addressed the comments. FYI I pushed some commits to resolve the CI issues.

@bahrmichael
Copy link
Copy Markdown
Contributor

I would wait for an update for Keegan's requested changes before doing my review pass if that's okay.

@keegancsmith keegancsmith force-pushed the peterguy/support-http_proxy branch from 6ab67e5 to 78eadd2 Compare March 2, 2026 10:00
@peterguy peterguy changed the base branch from main to peterguy/clean-up-config March 8, 2026 03:32
@peterguy peterguy force-pushed the peterguy/support-http_proxy branch from 78eadd2 to 54aada1 Compare March 8, 2026 03:32
@peterguy peterguy force-pushed the peterguy/clean-up-config branch from cab95e8 to 97c1b0a Compare March 10, 2026 01:53
@peterguy peterguy force-pushed the peterguy/support-http_proxy branch 4 times, most recently from 448305b to a0d8f91 Compare March 11, 2026 04:40
@peterguy peterguy force-pushed the peterguy/clean-up-config branch from 5ccd030 to 9ad25e5 Compare March 11, 2026 06:01
@peterguy peterguy force-pushed the peterguy/support-http_proxy branch from a0d8f91 to ed682d7 Compare March 11, 2026 06:11
@peterguy peterguy changed the title Add support for HTTP_PROXY, HTTPS_PROXY, and NO_PROXY feature: Add support for HTTP_PROXY, HTTPS_PROXY, and NO_PROXY Mar 12, 2026
@peterguy peterguy force-pushed the peterguy/support-http_proxy branch from 6259749 to 99ad843 Compare April 1, 2026 02:02
Copy link
Copy Markdown
Contributor

@bahrmichael bahrmichael left a comment

Choose a reason for hiding this comment

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

Thank you for simplifying this so much! I'm surprised that we can delete so much code, but as you said it still works after removing the socks5 code.

Is the PR description still up to date?

@peterguy peterguy marked this pull request as ready for review April 3, 2026 21:33
@peterguy
Copy link
Copy Markdown
Contributor Author

peterguy commented Apr 3, 2026

Description is accurate, Added some better smoke tests that I think are important to guard against future changes to withProxyTransport, even though the code is much more simple.

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.

3 participants