mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-28 23:06:43 -04:00
Use modern HttpClient
(cherry picked from commit 402f8b296f17bf161824ec5ff40d67d036d00d94)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Net.Http;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Common.Serializer;
|
||||
@@ -29,7 +30,7 @@ namespace NzbDrone.Core.Notifications.Discord
|
||||
.Accept(HttpAccept.Json)
|
||||
.Build();
|
||||
|
||||
request.Method = HttpMethod.POST;
|
||||
request.Method = HttpMethod.Post;
|
||||
request.Headers.ContentType = "application/json";
|
||||
request.SetContent(payload.ToJson());
|
||||
|
||||
|
||||
@@ -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.Web;
|
||||
using System.Xml.Linq;
|
||||
@@ -112,11 +113,11 @@ namespace NzbDrone.Core.Notifications.Goodreads
|
||||
// we need the url without the query to sign
|
||||
auth.RequestUrl = request.Url.SetQuery(null).FullUri;
|
||||
|
||||
if (builder.Method == HttpMethod.GET)
|
||||
if (builder.Method == HttpMethod.Get)
|
||||
{
|
||||
auth.Parameters = builder.QueryParams.ToDictionary(x => x.Key, x => x.Value);
|
||||
}
|
||||
else if (builder.Method == HttpMethod.POST)
|
||||
else if (builder.Method == HttpMethod.Post)
|
||||
{
|
||||
auth.Parameters = builder.FormData.ToDictionary(x => x.Name, x => Encoding.UTF8.GetString(x.ContentData));
|
||||
}
|
||||
@@ -172,7 +173,7 @@ namespace NzbDrone.Core.Notifications.Goodreads
|
||||
{
|
||||
var request = new Common.Http.HttpRequest(Settings.SigningUrl)
|
||||
{
|
||||
Method = HttpMethod.POST,
|
||||
Method = HttpMethod.Post,
|
||||
};
|
||||
request.Headers.Set("Content-Type", "application/json");
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
@@ -27,7 +28,7 @@ namespace NzbDrone.Core.Notifications.Join
|
||||
|
||||
public void SendNotification(string title, string message, JoinSettings settings)
|
||||
{
|
||||
var method = HttpMethod.GET;
|
||||
var method = HttpMethod.Get;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Http;
|
||||
using HttpMethod = NzbDrone.Common.Http.HttpMethod;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Mailgun
|
||||
{
|
||||
@@ -27,7 +27,7 @@ namespace NzbDrone.Core.Notifications.Mailgun
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = BuildRequest(settings, $"{settings.SenderDomain}/messages", HttpMethod.POST, title, message).Build();
|
||||
var request = BuildRequest(settings, $"{settings.SenderDomain}/messages", HttpMethod.Post, title, message).Build();
|
||||
_httpClient.Execute(request);
|
||||
}
|
||||
catch (HttpException ex)
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
@@ -100,7 +101,7 @@ namespace NzbDrone.Core.Notifications.PushBullet
|
||||
|
||||
var request = requestBuilder.Build();
|
||||
|
||||
request.Method = HttpMethod.GET;
|
||||
request.Method = HttpMethod.Get;
|
||||
request.Credentials = new BasicNetworkCredential(settings.ApiKey, string.Empty);
|
||||
|
||||
var response = _httpClient.Execute(request);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Net;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Common.Serializer;
|
||||
|
||||
@@ -22,7 +23,7 @@ namespace NzbDrone.Core.Notifications.SendGrid
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = BuildRequest(settings, "mail/send", HttpMethod.POST);
|
||||
var request = BuildRequest(settings, "mail/send", HttpMethod.Post);
|
||||
|
||||
var payload = new SendGridPayload
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Net.Http;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Common.Serializer;
|
||||
@@ -29,7 +30,7 @@ namespace NzbDrone.Core.Notifications.Slack
|
||||
.Accept(HttpAccept.Json)
|
||||
.Build();
|
||||
|
||||
request.Method = HttpMethod.POST;
|
||||
request.Method = HttpMethod.Post;
|
||||
request.Headers.ContentType = "application/json";
|
||||
request.SetContent(payload.ToJson());
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Xml.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
@@ -36,7 +37,7 @@ namespace NzbDrone.Core.Notifications.Subsonic
|
||||
public void Notify(SubsonicSettings settings, string message)
|
||||
{
|
||||
var resource = "addChatMessage";
|
||||
var request = GetSubsonicServerRequest(resource, HttpMethod.GET, settings);
|
||||
var request = GetSubsonicServerRequest(resource, HttpMethod.Get, settings);
|
||||
request.AddQueryParam("message", message);
|
||||
|
||||
var response = _httpClient.Execute(request.Build());
|
||||
@@ -48,7 +49,7 @@ namespace NzbDrone.Core.Notifications.Subsonic
|
||||
public void Update(SubsonicSettings settings)
|
||||
{
|
||||
var resource = "startScan";
|
||||
var request = GetSubsonicServerRequest(resource, HttpMethod.GET, settings);
|
||||
var request = GetSubsonicServerRequest(resource, HttpMethod.Get, settings);
|
||||
var response = _httpClient.Execute(request.Build());
|
||||
|
||||
_logger.Trace("Update response: {0}", response.Content);
|
||||
@@ -57,7 +58,7 @@ namespace NzbDrone.Core.Notifications.Subsonic
|
||||
|
||||
public string Version(SubsonicSettings settings)
|
||||
{
|
||||
var request = GetSubsonicServerRequest("ping", HttpMethod.GET, settings);
|
||||
var request = GetSubsonicServerRequest("ping", HttpMethod.Get, settings);
|
||||
var response = _httpClient.Execute(request.Build());
|
||||
|
||||
_logger.Trace("Version response: {0}", response.Content);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using NzbDrone.Common.Http;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Webhook
|
||||
{
|
||||
public enum WebhookMethod
|
||||
{
|
||||
POST = HttpMethod.POST,
|
||||
PUT = HttpMethod.PUT
|
||||
POST = 1,
|
||||
PUT = 2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Net;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Common.Serializer;
|
||||
@@ -27,7 +28,13 @@ namespace NzbDrone.Core.Notifications.Webhook
|
||||
.Accept(HttpAccept.Json)
|
||||
.Build();
|
||||
|
||||
request.Method = (HttpMethod)settings.Method;
|
||||
request.Method = settings.Method switch
|
||||
{
|
||||
(int)WebhookMethod.POST => HttpMethod.Post,
|
||||
(int)WebhookMethod.PUT => HttpMethod.Put,
|
||||
_ => throw new ArgumentOutOfRangeException($"Invalid Webhook method {settings.Method}")
|
||||
};
|
||||
|
||||
request.Headers.ContentType = "application/json";
|
||||
request.SetContent(body.ToJson());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user