mirror of https://github.com/Squidex/squidex.git
7 changed files with 113 additions and 135 deletions
@ -0,0 +1,45 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Net.Http; |
|||
using System.Threading.Tasks; |
|||
using Squidex.Infrastructure.Http; |
|||
|
|||
namespace Squidex.Domain.Apps.Core.HandleRules.Actions.Utils |
|||
{ |
|||
public static class HttpHelper |
|||
{ |
|||
public static async Task<(string Dump, Exception Exception)> OneWayRequestAsync(this HttpClient client, HttpRequestMessage request, string requestBody = null) |
|||
{ |
|||
HttpResponseMessage response = null; |
|||
try |
|||
{ |
|||
response = await client.SendAsync(request); |
|||
|
|||
var responseString = await response.Content.ReadAsStringAsync(); |
|||
|
|||
var requestDump = DumpFormatter.BuildDump(request, response, requestBody, responseString); |
|||
|
|||
Exception ex = null; |
|||
|
|||
if (!response.IsSuccessStatusCode) |
|||
{ |
|||
ex = new HttpRequestException($"Response code does not indicate success: {(int)response.StatusCode} ({response.StatusCode})."); |
|||
} |
|||
|
|||
return (requestDump, ex); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
var requestDump = DumpFormatter.BuildDump(request, response, requestBody, ex.ToString()); |
|||
|
|||
return (requestDump, ex); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Net.Http; |
|||
|
|||
namespace Squidex.Domain.Apps.Core.HandleRules |
|||
{ |
|||
public static class HttpClientPool |
|||
{ |
|||
private static readonly ClientPool<string, HttpClient> Pool = new ClientPool<string, HttpClient>(key => |
|||
{ |
|||
return new HttpClient { Timeout = TimeSpan.FromSeconds(2) }; |
|||
}); |
|||
|
|||
public static HttpClient GetHttpClient() |
|||
{ |
|||
return Pool.GetClient(string.Empty); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue