Skip to content

Commit

Permalink
[Mono.Android] AndroidMessageHandler should follow HTTP-308 redirects (
Browse files Browse the repository at this point in the history
…#8951)

Fixes: #8946

Context: 1e5bfa3

For some reason we skipped [`HttpStatusCode.PermanentRedirect`][0]
(HTTP-308) when handling redirects in 1e5bfa3.

Update `AndroidMessageHandler.HandleRedirect()` to follow an HTTP
redirect on HTTP-308 errors.

[0]: https://learn.microsoft.com/dotnet/api/system.net.httpstatuscode?view=net-8.0#system-net-httpstatuscode-permanentredirect
  • Loading branch information
simonrozsival authored and jonathanpeppers committed May 16, 2024
1 parent 96b6bb6 commit fa1b801
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ bool HandleRedirect (HttpStatusCode redirectCode, HttpURLConnection httpConnecti
// what to do with the response

case HttpStatusCode.TemporaryRedirect: // 307
case HttpStatusCode.PermanentRedirect: // 308
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,20 @@ public async Task ServerCertificateCustomValidationCallback_Redirects ()
Assert.IsTrue (result.IsSuccessStatusCode);
}

[Test]
public async Task AndroidMessageHandlerFollows308PermanentRedirect ()
{
int callbackCounter = 0;

var handler = new AndroidMessageHandler ();

var client = new HttpClient (handler);
var result = await client.GetAsync ("https://httpbin.org/redirect-to?url=https://www.microsoft.com/&status_code=308");

Assert.IsTrue (result.IsSuccessStatusCode);
Assert.AreEqual ("https://www.microsoft.com/", result.RequestMessage.RequestUri.ToString ());
}

private async Task AssertRejectsRemoteCertificate (Func<Task> makeRequest)
{
// there is a difference between the exception that's thrown in the .NET build and the legacy Xamarin
Expand Down

0 comments on commit fa1b801

Please sign in to comment.