-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[.NET6 undocumented breaking change] HttpConnectionPool is throwing exception instead of returning HttpResponseMessage #65305
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsDescriptionIn .NET 6 there is a significant change in Reproduction Steps
services
.AddHttpClient("HttpClientName")
.ConfigurePrimaryHttpMessageHandler(sp =>
{
var handler = new HttpClientHandler
{
Proxy = new WebProxy(proxyAddress),
UseProxy = true,
};
return handler;
});
var response = await client.SendAsync(httpRequest, cancellationToken);
Expected behavior
Actual behavior
Regression?Expected behaviour was present in .NET 5. Known WorkaroundsCurrently I am unaware of any workaround. ConfigurationNo response Other informationNo response
|
@geoffkizer, @wfurt could you take a look? |
The rationale for this change is described in the linked issue, #48679. Given the rationale there, it's unlikely we would revert this. We could certainly look at how to expose more information about the response received from the proxy here, or possibly provide some sort of callback to allow you to inspect the response yourself. It would be helpful to have more information about what you are trying to do here. It sounds like you are trying to access various proxies and determine if they are usable or not? What responses do you expect and what response headers do you care about? What action, if any, do you take after a failure? Possible workarounds: |
This issue has been marked |
@geoffkizer thank you for your answer. Providing an asynchronous callback would be a perfect soultion for my team. In our scenario we are communicating with outside world via proxy which can based on some business rules cut off that communication by returning 403 to caller. If such thing happend we were examinig response headers and body to decide how to handle such situation. Now the only thing we have is exception with msg informing about proxy address and response status code. Choosing logic to perform based on exception message seems like an antipattern. (1) Reaching some endpoints is only avaiable via https so it is not a solution for us PS I belive there is a typo in exception msg you are throwing in
|
@geoffkizer Should we consider adding a setting toggle here to let dev select the pattern? Or could we add the status code to the HttpRequestException?
The point here is that we don't know whether the user has a proxy or not, so your advice (2) is not applicable. Besides, I am curious why we only do this update on HTTPS requests, but not HTTP requests? |
See the detailed description here #48679 (comment) With http, you intentionally opt out of security, and there's by-design no way to tell where the response actually came from. |
Triage: it seems like we need to add documentation. This should be possibly solved by #66329. |
Description
In .NET 6 there is a significant change in
HttpConnectionPool
. Exception will be thrown in palce where in .NET 5HttpResponseMessage
would be returned (https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs#L1553). It was introduced due to #48679. It is a major breaking change for my application because in previous versions after sending a request withHttpClient
via proxy if we received response different than 200 we had conditional logic checking response to determine how to handle this situation. We were for example checking not only response status code but also headers that are now unaviable. Is there a workaround to preserve backward compatibility? Also was this change well documented? I believe that I didn't stumble upon it reading release notes and as pointed above it can be breaking change for some application.Reproduction Steps
HttpClient
using ProxyIHttpClientFactory
resolve client and send request to desirable URL.Expected behavior
HttpResponseMessage
is returned intead of exception being thrown. It allows for processing that response.Actual behavior
HttpRequestException
is thrown and noHttpResponseMessage
is avaible for processing.Regression?
Expected behaviour was present in .NET 5.
Known Workarounds
Currently I am unaware of any workaround.
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: