-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reinstate RedirectWebClient to fix redirects on Mono
- Loading branch information
Showing
2 changed files
with
69 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#if NETFRAMEWORK | ||
|
||
using System; | ||
using System.Net; | ||
|
||
namespace CKAN | ||
{ | ||
// HttpClient doesn't handle redirects well on Mono, but net7.0 considers WebClient obsolete | ||
internal sealed class RedirectWebClient : WebClient | ||
{ | ||
public RedirectWebClient() | ||
{ | ||
Headers.Add("User-Agent", Net.UserAgentString); | ||
} | ||
|
||
protected override WebRequest GetWebRequest(Uri address) | ||
{ | ||
var webRequest = (HttpWebRequest)base.GetWebRequest(address); | ||
webRequest.AllowAutoRedirect = false; | ||
webRequest.Method = "HEAD"; | ||
|
||
return webRequest; | ||
} | ||
} | ||
} | ||
|
||
#endif |