Add PlayFab Client endpoints

This commit is contained in:
AeonLucid
2021-10-31 03:30:17 +02:00
parent 7fbf7f225e
commit bcc675489e
29 changed files with 1001 additions and 3 deletions
@@ -0,0 +1,57 @@
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace Prospect.Server.Api.Middleware
{
public class RequestLoggerMiddleware
{
private readonly ILogger<RequestLoggerMiddleware> _logger;
private readonly RequestDelegate _next;
public RequestLoggerMiddleware(ILogger<RequestLoggerMiddleware> logger, RequestDelegate next)
{
_logger = logger;
_next = next;
}
public async Task Invoke(HttpContext context)
{
var body = await RequestAsync(context.Request);
if (context.Request.Method == "POST")
{
_logger.LogDebug("URL {Url} Body {Body}", context.Request.GetDisplayUrl(), body);
}
await _next(context);
}
private static async Task<string> RequestAsync(HttpRequest request)
{
request.EnableBuffering();
try
{
using (var reader = new StreamReader(request.Body, Encoding.UTF8, false, 4096, true))
{
var body = await reader.ReadToEndAsync();
if (body.StartsWith("{"))
{
return JsonConvert.SerializeObject(JsonConvert.DeserializeObject(body), Formatting.Indented);
}
return body;
}
}
finally
{
request.Body.Position = 0;
}
}
}
}