Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2017-10-23 22:31:51 +0300
committerStephen Toub <stoub@microsoft.com>2017-10-25 20:23:59 +0300
commitddfab940fcc2d571c2da85250c13e457ab1933a2 (patch)
tree38a6685566ecfca46f10e9b03841bae2b272c00f /src
parent3c17c2251b4bda98273e57ef153cc9bc267805c8 (diff)
Don't fail a redirect that's missing a Location header
Diffstat (limited to 'src')
-rw-r--r--src/System.Net.Http/src/Resources/Strings.resx5
-rw-r--r--src/System.Net.Http/src/System/Net/Http/Managed/AutoRedirectHandler.cs3
-rw-r--r--src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs30
3 files changed, 33 insertions, 5 deletions
diff --git a/src/System.Net.Http/src/Resources/Strings.resx b/src/System.Net.Http/src/Resources/Strings.resx
index 90a5d97b9c..129ef9fd5f 100644
--- a/src/System.Net.Http/src/Resources/Strings.resx
+++ b/src/System.Net.Http/src/Resources/Strings.resx
@@ -363,9 +363,6 @@
<data name="net_http_feature_UWPClientCertSupportRequiresCertInPersonalCertificateStore" xml:space="preserve">
<value>Client certificate was not found in the personal (\"MY\") certificate store. In UWP, client certificates are only supported if they have been added to that certificate store.</value>
</data>
- <data name="net_http_headers_missing_location" xml:space="preserve">
- <value>The response code indicates a redirect, but the 'Location' header is missing.</value>
- </data>
<data name="net_http_max_redirects" xml:space="preserve">
<value>The maximum number of redirects was exceeded.</value>
</data>
@@ -387,4 +384,4 @@
<data name="net_ssl_app_protocols_invalid" xml:space="preserve">
<value>The application protocol list is invalid.</value>
</data>
-</root> \ No newline at end of file
+</root>
diff --git a/src/System.Net.Http/src/System/Net/Http/Managed/AutoRedirectHandler.cs b/src/System.Net.Http/src/System/Net/Http/Managed/AutoRedirectHandler.cs
index a35175acaa..7605616781 100644
--- a/src/System.Net.Http/src/System/Net/Http/Managed/AutoRedirectHandler.cs
+++ b/src/System.Net.Http/src/System/Net/Http/Managed/AutoRedirectHandler.cs
@@ -72,7 +72,8 @@ namespace System.Net.Http
Uri location = response.Headers.Location;
if (location == null)
{
- throw new HttpRequestException(SR.net_http_headers_missing_location);
+ // No location header. Nothing to redirect to.
+ break;
}
if (!location.IsAbsoluteUri)
diff --git a/src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs b/src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs
index 9f2aa8db2f..107918623f 100644
--- a/src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs
+++ b/src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs
@@ -635,6 +635,36 @@ namespace System.Net.Http.Functional.Tests
}
}
+ [Fact]
+ public async Task GetAsync_AllowAutoRedirectTrue_RedirectWithoutLocation_ReturnsOriginalResponse()
+ {
+ // [ActiveIssue(24819, TestPlatforms.Windows)]
+ if (PlatformDetection.IsWindows && PlatformDetection.IsNetCore && !UseManagedHandler)
+ {
+ return;
+ }
+
+ HttpClientHandler handler = CreateHttpClientHandler();
+ handler.AllowAutoRedirect = true;
+ using (var client = new HttpClient(handler))
+ {
+ await LoopbackServer.CreateServerAsync(async (server, url) =>
+ {
+ Task<HttpResponseMessage> getTask = client.GetAsync(url);
+ Task<List<string>> serverTask = LoopbackServer.ReadRequestAndSendResponseAsync(server,
+ $"HTTP/1.1 302 OK\r\n" +
+ $"Date: {DateTimeOffset.UtcNow:R}\r\n" +
+ "\r\n");
+ await TestHelper.WhenAllCompletedOrAnyFailed(getTask, serverTask);
+
+ using (HttpResponseMessage response = await getTask)
+ {
+ Assert.Equal(302, (int)response.StatusCode);
+ }
+ });
+ }
+ }
+
[OuterLoop] // TODO: Issue #11345
[Fact]
public async Task GetAsync_AllowAutoRedirectTrue_RedirectToUriWithParams_RequestMsgUriSet()