Use native HttpMethod

This commit is contained in:
Qstick
2022-01-03 00:28:20 -06:00
parent e04133d34a
commit 76b6b0dead
56 changed files with 198 additions and 147 deletions
@@ -60,7 +60,7 @@ namespace NzbDrone.Core.Indexers.Definitions
var mainPage = await ExecuteAuth(new HttpRequest(Settings.BaseUrl));
requestBuilder.Method = Common.Http.HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
requestBuilder.SetCookies(mainPage.GetCookies());
@@ -167,7 +167,7 @@ namespace NzbDrone.Core.Indexers.Definitions
if (isSearch)
{
request.HttpRequest.Method = NzbDrone.Common.Http.HttpMethod.POST;
request.HttpRequest.Method = HttpMethod.Post;
var postData = new NameValueCollection
{
{ "do", "search" },
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using AngleSharp.Html.Parser;
@@ -57,7 +58,7 @@ namespace NzbDrone.Core.Indexers.Definitions
};
var loginPage = await ExecuteAuth(new HttpRequest(LoginUrl));
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
requestBuilder.SetCookies(loginPage.GetCookies());
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using AngleSharp.Html.Parser;
@@ -56,7 +57,7 @@ namespace NzbDrone.Core.Indexers.Definitions
AllowAutoRedirect = true
};
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
var cookies = Cookies;
@@ -1,5 +1,6 @@
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using FluentValidation.Results;
using NLog;
@@ -105,7 +106,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz
LogResponseContent = true
};
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
var authLoginRequest = requestBuilder
+2 -1
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -55,7 +56,7 @@ namespace NzbDrone.Core.Indexers.Definitions
AllowAutoRedirect = true
};
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
var cookies = Cookies;
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using AngleSharp.Dom;
@@ -79,7 +80,7 @@ namespace NzbDrone.Core.Indexers.Definitions
var loginPage = await ExecuteAuth(new HttpRequest(LoginUrl));
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
requestBuilder.SetCookies(loginPage.GetCookies());
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using FluentValidation;
using Newtonsoft.Json;
using NLog;
@@ -110,7 +111,7 @@ namespace NzbDrone.Core.Indexers.Definitions
var request = new HttpRequest(searchUrl, HttpAccept.Json);
request.Headers.Add("Content-type", "application/json");
request.Method = HttpMethod.POST;
request.Method = HttpMethod.Post;
request.SetContent(body.ToJson());
var indexerRequest = new IndexerRequest(request);
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using AngleSharp.Html.Dom;
@@ -184,7 +185,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
var requestBuilder = new HttpRequestBuilder(loginUrl)
{
LogResponseContent = true,
Method = HttpMethod.POST,
Method = HttpMethod.Post,
AllowAutoRedirect = true,
SuppressHttpError = true,
Encoding = _encoding
@@ -329,7 +330,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
var requestBuilder = new HttpRequestBuilder(captchaUrl.ToString())
{
LogResponseContent = true,
Method = HttpMethod.GET,
Method = HttpMethod.Get,
Encoding = _encoding
};
@@ -394,7 +395,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
var requestBuilder = new HttpRequestBuilder(submitUrl.ToString())
{
LogResponseContent = true,
Method = HttpMethod.POST,
Method = HttpMethod.Post,
AllowAutoRedirect = true,
Encoding = _encoding
};
@@ -423,7 +424,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
var requestBuilder = new HttpRequestBuilder(submitUrl.ToString())
{
LogResponseContent = true,
Method = HttpMethod.POST,
Method = HttpMethod.Post,
AllowAutoRedirect = true,
SuppressHttpError = true,
Encoding = _encoding
@@ -466,7 +467,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
var requestBuilder = new HttpRequestBuilder(loginUrl)
{
LogResponseContent = true,
Method = HttpMethod.GET,
Method = HttpMethod.Get,
SuppressHttpError = true,
Encoding = _encoding
};
@@ -491,7 +492,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
var requestBuilder = new HttpRequestBuilder(loginUrl)
{
LogResponseContent = true,
Method = HttpMethod.GET,
Method = HttpMethod.Get,
SuppressHttpError = true,
Encoding = _encoding
};
@@ -565,7 +566,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
var requestBuilder = new HttpRequestBuilder(loginUrl.AbsoluteUri)
{
LogResponseContent = true,
Method = HttpMethod.GET,
Method = HttpMethod.Get,
Encoding = _encoding
};
@@ -666,21 +667,21 @@ namespace NzbDrone.Core.Indexers.Cardigann
Dictionary<string, string> pairs = null;
var queryCollection = new NameValueCollection();
var method = HttpMethod.GET;
var method = HttpMethod.Get;
if (string.Equals(request.Method, "post", StringComparison.OrdinalIgnoreCase))
{
method = HttpMethod.POST;
method = HttpMethod.Post;
pairs = new Dictionary<string, string>();
}
foreach (var input in request.Inputs)
{
var value = ApplyGoTemplateText(input.Value, variables);
if (method == HttpMethod.GET)
if (method == HttpMethod.Get)
{
queryCollection.Add(input.Key, value);
}
else if (method == HttpMethod.POST)
else if (method == HttpMethod.Post)
{
pairs.Add(input.Key, value);
}
@@ -707,7 +708,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
httpRequest.Method = method;
// Add form data for POST requests
if (method == HttpMethod.POST)
if (method == HttpMethod.Post)
{
foreach (var param in pairs)
{
@@ -724,7 +725,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
public async Task<HttpRequest> DownloadRequest(Uri link)
{
Cookies = GetCookies();
var method = HttpMethod.GET;
var method = HttpMethod.Get;
var headers = new Dictionary<string, string>();
var variables = GetBaseTemplateVariables();
@@ -759,7 +760,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
if (download.Method == "post")
{
method = HttpMethod.POST;
method = HttpMethod.Post;
}
if (download.Infohash != null)
@@ -1014,11 +1015,11 @@ namespace NzbDrone.Core.Indexers.Cardigann
// HttpUtility.UrlPathEncode seems to only encode spaces, we use UrlEncode and replace + with %20 as a workaround
var searchUrl = ResolvePath(ApplyGoTemplateText(searchPath.Path, variables, WebUtility.UrlEncode).Replace("+", "%20")).AbsoluteUri;
var queryCollection = new List<KeyValuePair<string, string>>();
var method = HttpMethod.GET;
var method = HttpMethod.Get;
if (string.Equals(searchPath.Method, "post", StringComparison.OrdinalIgnoreCase))
{
method = HttpMethod.POST;
method = HttpMethod.Post;
}
var inputsList = new List<Dictionary<string, string>>();
@@ -1064,7 +1065,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
}
}
if (method == HttpMethod.GET)
if (method == HttpMethod.Get)
{
if (queryCollection.Count > 0)
{
@@ -1079,7 +1080,7 @@ namespace NzbDrone.Core.Indexers.Cardigann
requestbuilder.Method = method;
// Add FormData for searchs that POST
if (method == HttpMethod.POST)
if (method == HttpMethod.Post)
{
foreach (var param in queryCollection)
{
@@ -1,4 +1,5 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using NLog;
using NzbDrone.Common.Http;
@@ -56,7 +57,7 @@ namespace NzbDrone.Core.Indexers.Gazelle
LogResponseContent = true
};
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
var cookies = Cookies;
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
@@ -50,7 +51,7 @@ namespace NzbDrone.Core.Indexers.HDBits
.Resource("/api/torrents")
.Build();
request.Method = HttpMethod.POST;
request.Method = HttpMethod.Post;
const string appJson = "application/json";
request.Headers.Accept = appJson;
request.Headers.ContentType = appJson;
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -57,7 +58,7 @@ namespace NzbDrone.Core.Indexers.Definitions
AllowAutoRedirect = true
};
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
var cookies = Cookies;
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using AngleSharp.Html.Parser;
@@ -52,7 +53,7 @@ namespace NzbDrone.Core.Indexers.Definitions
LogResponseContent = true
};
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
var cookies = Cookies;
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using AngleSharp.Html.Parser;
using FluentValidation;
@@ -54,7 +55,7 @@ namespace NzbDrone.Core.Indexers.Definitions
LogResponseContent = true
};
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
var cookies = Cookies;
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -53,7 +54,7 @@ namespace NzbDrone.Core.Indexers.Definitions
LogResponseContent = true
};
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
var cookies = Cookies;
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Xml;
using System.Xml.Linq;
using NLog;
@@ -50,7 +51,7 @@ namespace NzbDrone.Core.Indexers.Newznab
var request = new HttpRequest(url, HttpAccept.Rss);
request.AllowAutoRedirect = true;
request.Method = HttpMethod.GET;
request.Method = HttpMethod.Get;
HttpResponse response;
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -79,7 +80,7 @@ namespace NzbDrone.Core.Indexers.Definitions
{
LogResponseContent = true,
AllowAutoRedirect = true,
Method = HttpMethod.POST
Method = HttpMethod.Post
};
var authLoginCheckRequest = requestBuilder3
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -52,7 +53,7 @@ namespace NzbDrone.Core.Indexers.Definitions
{
LogResponseContent = true,
AllowAutoRedirect = true,
Method = HttpMethod.POST
Method = HttpMethod.Post
};
var authLoginRequest = requestBuilder
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -59,7 +60,7 @@ namespace NzbDrone.Core.Indexers.Definitions
var loginPage = await ExecuteAuth(new HttpRequest(Settings.BaseUrl + "login.php"));
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
requestBuilder.SetCookies(loginPage.GetCookies());
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using AngleSharp.Html.Parser;
using FluentValidation;
@@ -58,7 +59,7 @@ namespace NzbDrone.Core.Indexers.Definitions
var loginPage = await ExecuteAuth(new HttpRequest(Settings.BaseUrl + "login.php"));
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
requestBuilder.SetCookies(loginPage.GetCookies());
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -57,7 +58,7 @@ namespace NzbDrone.Core.Indexers.Definitions
AllowAutoRedirect = true
};
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
var cookies = Cookies;
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Mime;
using System.Text;
using System.Threading.Tasks;
@@ -75,7 +76,7 @@ namespace NzbDrone.Core.Indexers.Definitions
{
LogResponseContent = true,
AllowAutoRedirect = true,
Method = HttpMethod.POST,
Method = HttpMethod.Post,
};
var request = requestBuilder.Build();
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -57,7 +58,7 @@ namespace NzbDrone.Core.Indexers.Definitions
{
var requestBuilder = new HttpRequestBuilder(string.Format("{0}/{1}", Settings.BaseUrl.TrimEnd('/'), "checkpoint/API"))
{
Method = HttpMethod.POST,
Method = HttpMethod.Post,
LogResponseContent = true,
AllowAutoRedirect = true
};
@@ -77,7 +78,7 @@ namespace NzbDrone.Core.Indexers.Definitions
var requestBuilder2 = new HttpRequestBuilder(string.Format("{0}/{1}", Settings.BaseUrl.TrimEnd('/'), "checkpoint/"))
{
Method = HttpMethod.POST,
Method = HttpMethod.Post,
LogResponseContent = true,
AllowAutoRedirect = true
};
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -59,7 +60,7 @@ namespace NzbDrone.Core.Indexers.Definitions
AllowAutoRedirect = true
};
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
var cookies = Cookies;
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using FluentValidation;
@@ -54,7 +55,7 @@ namespace NzbDrone.Core.Indexers.Definitions
LogResponseContent = true
};
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
var cookies = Cookies;
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using AngleSharp.Html.Parser;
@@ -63,7 +64,7 @@ namespace NzbDrone.Core.Indexers.Definitions
var json1 = JObject.Parse(loginPage.Content);
var captchaSelection = json1["images"][0]["hash"];
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
requestBuilder.SetCookies(loginPage.GetCookies());
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
@@ -79,7 +80,7 @@ namespace NzbDrone.Core.Indexers.Definitions
LogResponseContent = true
};
requestBuilder.Method = HttpMethod.POST;
requestBuilder.Method = HttpMethod.Post;
requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
requestBuilder.SetCookies(loginPage.GetCookies());
@@ -102,7 +103,7 @@ namespace NzbDrone.Core.Indexers.Definitions
LogResponseContent = true
};
requestBuilder2.Method = HttpMethod.POST;
requestBuilder2.Method = HttpMethod.Post;
requestBuilder2.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15);
requestBuilder2.SetCookies(response.GetCookies());