Skip to content

Commit

Permalink
Cache permanent redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed May 31, 2021
1 parent c76bef5 commit c8ba80a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Core/Net/Net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ protected override WebRequest GetWebRequest(Uri address)
log.InfoFormat("Setting MIME type {0}", mimeType);
Headers.Add("Accept", mimeType);
}
if (permanentRedirects.TryGetValue(address, out Uri redirUri))
{
// Obey a previously received permanent redirect
address = redirUri;
}
var request = base.GetWebRequest(address);
if (request is HttpWebRequest hwr)
{
Expand Down Expand Up @@ -417,6 +422,7 @@ protected override WebResponse GetWebResponse(WebRequest request)
log.InfoFormat("Host mismatch, purging token for redirect");
Headers.Remove("Authorization");
}
permanentRedirects.Add(request.RequestUri, redirUri);
return GetWebResponse(GetWebRequest(redirUri));
}
}
Expand All @@ -425,6 +431,7 @@ protected override WebResponse GetWebResponse(WebRequest request)

private int timeout;
private string mimeType;
private Dictionary<Uri, Uri> permanentRedirects = new Dictionary<Uri, Uri>();
}

// HACK: The ancient WebClient doesn't support setting the request type to HEAD and WebRequest doesn't support
Expand Down

0 comments on commit c8ba80a

Please sign in to comment.