diff --git a/src/NzbDrone.Common/Http/HttpClient.cs b/src/NzbDrone.Common/Http/HttpClient.cs index 175448e43..2824a8f94 100644 --- a/src/NzbDrone.Common/Http/HttpClient.cs +++ b/src/NzbDrone.Common/Http/HttpClient.cs @@ -60,8 +60,7 @@ public HttpResponse Execute(HttpRequest request) if (request.AllowAutoRedirect && response.HasHttpRedirect) { - var autoRedirectChain = new List(); - autoRedirectChain.Add(request.Url.ToString()); + var autoRedirectChain = new List { request.Url.ToString() }; do { @@ -75,6 +74,14 @@ public HttpResponse Execute(HttpRequest request) throw new WebException($"Too many automatic redirections were attempted for {autoRedirectChain.Join(" -> ")}", WebExceptionStatus.ProtocolError); } + // 302 or 303 should default to GET on redirect even if POST on original + if (RequestRequiresForceGet(response.StatusCode, response.Request.Method)) + { + request.Method = HttpMethod.Get; + request.ContentData = null; + request.ContentSummary = null; + } + response = ExecuteRequest(request, cookieContainer); } while (response.HasHttpRedirect); @@ -105,6 +112,16 @@ public HttpResponse Execute(HttpRequest request) return response; } + private static bool RequestRequiresForceGet(HttpStatusCode statusCode, HttpMethod requestMethod) + { + return statusCode switch + { + HttpStatusCode.Moved or HttpStatusCode.Found or HttpStatusCode.MultipleChoices => requestMethod == HttpMethod.Post, + HttpStatusCode.SeeOther => requestMethod != HttpMethod.Get && requestMethod != HttpMethod.Head, + _ => false, + }; + } + private HttpResponse ExecuteRequest(HttpRequest request, CookieContainer cookieContainer) { foreach (var interceptor in _requestInterceptors)