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 Unauthorized instead of 407
- 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:password@proxy.example.com:8080"
dotnet restore # Fails with 401 or timeout
Direct 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
Description
Context
In the https://claude.ai/code environment, the proxy doesn't work for
dotnet restore. This is becausedotnet restoreexpect 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_PROXYwith credentials in the URL),dotnet restoreand other HttpClient-based operations fail with401 Unauthorized.Root cause: The current implementation waits for a
407 Proxy Authentication Requiredresponse before sending credentials. However, many proxies:401 Unauthorizedinstead of407407, making retry impossible for CONNECT tunnelsReproduction:
Direct test showing the issue:
Solution
Modify
AuthenticationHelper.SendWithProxyAuthAsyncto proactively sendProxy-Authorization: Basic ...header on the first request whenNetworkCredentialis 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
Reproduction Steps
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