runtime: HttpClient With Proxy did not handle the Proxy 407 auth flow on Linux OS

Description

Hi, I`m developing an application which using HttpClient with HttpClientHandler to manage my Http network connection. While setting my WebProxy on the HttpClientHandler I getting errors of 407 although my Proxy credentials are correct.

see a code snip:

foo(Uri? iProxyUri, NetworkCredential iProxyCredentials){
       CredentialCache cache = [];
       
       _ = cache.TryAdd(iProxyUri, iProxyCredentials);
        
         HttpClientHandler handler = new()
        {
            AllowAutoRedirect = false, // we want to handle the redirect 
            ServerCertificateCustomValidationCallback = (iRequest,
                                                         _1,
                                                         _2,
                                                         iErrors) => true,
            Proxy = new WebProxy(iProxyUri, false)
            {
                Credentials = iProxyCredentials,
                UseDefaultCredentials = false
            },
            SslProtocols = MySslProtocol,
            UseProxy = true,
            DefaultProxyCredentials = cache,
            Credentials = cache,
            UseDefaultCredentials = false,
            // PreAuthenticate = true
        };
        using HttpClient client = new(handler)
        {
            Timeout = TimeSpan.FromMinutes(5)
        };
}

Reproduction Steps

  1. Create HttpClient with HttpClientHandler which contains proxy that require username and password .
  2. Make API call to https://example.com

Expected behavior

407 response will be handle by the client handler and credentials should pass to the proxy server

Actual behavior

Received 407 response although client handler contains the proxy credentials

Regression?

Yes, I have an application with more or less the same code that running on .net 6 and I don`t see this issue there

Known Workarounds

No response

Configuration

No response

Other information

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 16 (8 by maintainers)

Most upvoted comments

also, just to clarify - the .net 6 app also never worked properly with the proxy on Linux. sorry for the confusion

@wfurt our cache.TryAdd tries to add all types

image

also, as @kashti3 mentioned, we have the same app (.net 8) running on windows under the same policies and using the same proxy with same creds and all works as expected.

on our customer proxy logs we saw that the CONNECT request is being sent without the required creds. we have ran a Curl request from the linux machine to the same url with the same proxy config, and we got a valid response.

BTW, powershell also fails (as expected)