Skip to content
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

Store status code in exception for ProxyTunnelError #105610

Merged
merged 5 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ public async Task AuthenticatedProxyTunnelRequest_PostAsyncWithNoCreds_Throws()
using (HttpClient client = CreateHttpClient(handler))
{
HttpRequestException e = await Assert.ThrowsAnyAsync<HttpRequestException>(async () => await client.PostAsync("https://nosuchhost.invalid", new StringContent(content)));
Assert.Contains("407", e.Message);
Assert.Equal(HttpRequestError.ProxyTunnelError, e.HttpRequestError);
Assert.Equal(HttpStatusCode.ProxyAuthenticationRequired, e.StatusCode);
Assert.Contains(((int)HttpStatusCode.ProxyAuthenticationRequired).ToString(), e.Message);
}
}
}
Expand All @@ -313,7 +315,9 @@ public async Task Proxy_SslProxyUnsupported_Throws()
{
handler.Proxy = new WebProxy($"https://{Guid.NewGuid():N}");

await Assert.ThrowsAsync<HttpRequestException>(() => client.GetAsync($"http://{Guid.NewGuid():N}"));
HttpRequestException e = await Assert.ThrowsAsync<HttpRequestException>(() => client.GetAsync($"http://{Guid.NewGuid():N}"));
Assert.Equal(HttpRequestError.ProxyTunnelError, e.HttpRequestError);
Assert.Null(e.StatusCode);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ private async ValueTask<Stream> EstablishProxyTunnelAsync(bool async, Cancellati
if (tunnelResponse.StatusCode != HttpStatusCode.OK)
{
tunnelResponse.Dispose();
throw new HttpRequestException(HttpRequestError.ProxyTunnelError, SR.Format(SR.net_http_proxy_tunnel_returned_failure_status_code, _proxyUri, (int)tunnelResponse.StatusCode));
throw new HttpRequestException(HttpRequestError.ProxyTunnelError, SR.Format(SR.net_http_proxy_tunnel_returned_failure_status_code, _proxyUri, (int)tunnelResponse.StatusCode), statusCode: tunnelResponse.StatusCode);
}

try
Expand Down
Loading