-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Description
Context
In the https://claude.ai/code environment, the proxy doesn't work for dotnet restore. This is because dotnet restore expect the proxy to respond with an HTTP 407 before it sends the authentication headers, but this one does not.
Problem
When using an authenticated HTTP proxy configured via environment variables (HTTP_PROXY/HTTPS_PROXY with credentials in the URL), dotnet restore and other HttpClient-based operations fail with 401 Unauthorized.
Root cause: The current implementation waits for a 407 Proxy Authentication Required response before sending credentials. However, many proxies:
- Return
401 Unauthorizedinstead of407 - Simply drop/timeout unauthenticated connections without any response
- Close the connection after
407, making retry impossible for CONNECT tunnels
Reproduction:
export HTTPS_PROXY="http://user:[email protected]:8080"
dotnet restore # Fails with 401 or timeoutDirect test showing the issue:
# Without Proxy-Authorization header:
CONNECT example.com:443 HTTP/1.1 → HTTP/1.1 401 Unauthorized
# With Proxy-Authorization header:
CONNECT example.com:443 HTTP/1.1
Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==
→ HTTP/1.1 200 OK
Solution
Modify AuthenticationHelper.SendWithProxyAuthAsync to proactively send Proxy-Authorization: Basic ... header on the first request when NetworkCredential is available, rather than waiting for a challenge.
This matches the behavior of curl, wget, and other HTTP clients that send proxy auth proactively.
Affected scenarios
- Corporate proxies requiring authentication
- Container environments with authenticated egress proxies
- CI/CD pipelines behind authenticated proxies
Reproduction Steps
- Fork https://github.com/dotnet/runtime/
- Open https://claude.ai/code
- Choose "runtime" and type "run the tests" and choose "Full Internet" as the environment then press enter
Expected behavior
The tests run
Actual behavior
NuGet won't download
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response