Use named HttpClients (#15375)
* Use named HttpClients * Register as named client * Set headers on request message. * Add User agent header to http client * Add headers within Try-catch * Add using for HttpResponseMessage * Update src/Umbraco.Infrastructure/BackgroundJobs/Jobs/WebhookFiring.cs Co-authored-by: Ronald Barendse <ronald@barend.se> * Update src/Umbraco.Infrastructure/BackgroundJobs/Jobs/WebhookFiring.cs Co-authored-by: Kenn Jacobsen <kja@umbraco.dk> * Log key instead of entire webhook * Update src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs Co-authored-by: Ronald Barendse <ronald@barend.se> * Create constant for User agent header name * Update src/Umbraco.Infrastructure/BackgroundJobs/Jobs/WebhookFiring.cs Co-authored-by: Ronald Barendse <ronald@barend.se> * Use datetime.now --------- Co-authored-by: Zeegaan <nge@umbraco.dk> Co-authored-by: Ronald Barendse <ronald@barend.se> Co-authored-by: Kenn Jacobsen <kja@umbraco.dk>
This commit is contained in:
@@ -14,5 +14,18 @@ public static partial class Constants
|
||||
/// Name for http client which ignores certificate errors.
|
||||
/// </summary>
|
||||
public const string IgnoreCertificateErrors = "Umbraco:HttpClients:IgnoreCertificateErrors";
|
||||
|
||||
/// <summary>
|
||||
/// Name for http client which sends webhook requests.
|
||||
/// </summary>
|
||||
public const string WebhookFiring = "Umbraco:HttpClients:WebhookFiring";
|
||||
|
||||
public static class Headers
|
||||
{
|
||||
/// <summary>
|
||||
/// User agent name for the product name.
|
||||
/// </summary>
|
||||
public const string UserAgentProductName = "Umbraco-Cms";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public abstract class OEmbedProviderBase : IEmbedProvider
|
||||
if (_httpClient == null)
|
||||
{
|
||||
_httpClient = new HttpClient();
|
||||
_httpClient.DefaultRequestHeaders.UserAgent.TryParseAdd("Umbraco-CMS");
|
||||
_httpClient.DefaultRequestHeaders.UserAgent.TryParseAdd(Constants.HttpClients.Headers.UserAgentProductName);
|
||||
}
|
||||
|
||||
using (var request = new HttpRequestMessage(HttpMethod.Get, url))
|
||||
|
||||
Reference in New Issue
Block a user