twitchax / AspNetCore.Proxy

ASP.NET Core Proxies made easy.
MIT License
505 stars 80 forks source link

Authentication failed because the connection could not be reused #70

Open dsivori1 opened 3 years ago

dsivori1 commented 3 years ago

Trying to set up a proxy to a Rest Service that used NTLM Authentication. I don't know that you can resolve it, but I'm getting this error:

Authentication failed because the connection could not be reused.

at System.Net.Http.HttpConnection.DrainResponseAsync(HttpResponseMessage response) at System.Net.Http.AuthenticationHelper.SendWithNtAuthAsync(HttpRequestMessage request, Uri authUri, ICredentials credentials, Boolean isProxyAuth, HttpConnection connection, HttpConnectionPool connectionPool, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.AuthenticationHelper.SendWithAuthAsync(HttpRequestMessage request, Uri authUri, ICredentials credentials, Boolean preAuthenticate, Boolean isProxyAuth, Boolean doRequestAuth, HttpConnectionPool pool, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) at AspNetCore.Proxy.HttpExtensions.ExecuteHttpProxyOperationAsync(HttpContext context, HttpProxy httpProxy) SsrsController.cs.txt Startup.cs.txt

twitchax commented 3 years ago

Interesting. I will probably need to write a test to repro this, and then debug. If you could write a test, that would help, as well.

Preliminarily, it sounds a bit like #70.

Eweol commented 1 year ago

I have the same issue now.

I figured out some more informations which could maybe help to fix that. This error only appears if the client and server uses HTTPv2 as protocol. With HTTPv1.1 everything is working like expected.

Eweol commented 1 year ago

Figured out, it can be solved with solution of #91.

Can be closed

twitchax commented 1 year ago

Interesting. Maybe I should add a section about SSRS to the README.

Would you mind helping me out with it since I would yield to your expertise about why this happens.

Eweol commented 1 year ago

I don't think that it is only related to SSRS (even if I had the problem as well with SSRS), but it seems like the following. If you setup a request with HTTP v1 / HTTP v1.1 than everything is quiet fine without any issue because you have set default wise the header "Connection" to "keep-alive". If you now setup same call with HTTP v2 / HTTP v3 this header is not attached because it is not allowed and not needed within these protocols. The proxy now copies all the headers from that request but not the "Connection" header because it is not there. related to that the NTLM authentication cannot be fulfilled because the connection will be interrupted.

I don't know if that problem can also be solved by recognising the HTTP protocol version and use same than the initial one.