You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
847 B
30 lines
847 B
using Coldairarrow.Util;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Coldairarrow.Api
|
|
{
|
|
public class RequestBodyMiddleware
|
|
{
|
|
private readonly RequestDelegate _next;
|
|
|
|
public RequestBodyMiddleware(RequestDelegate next)
|
|
{
|
|
_next = next;
|
|
}
|
|
|
|
public async Task Invoke(HttpContext context)
|
|
{
|
|
if ((context.Request.ContentType ?? string.Empty).Contains("application/json"))
|
|
{
|
|
context.Request.EnableBuffering();
|
|
string body = await context.Request.Body?.ReadToStringAsync(Encoding.UTF8);
|
|
context.RequestServices.GetService<RequestBody>().Body = body;
|
|
}
|
|
|
|
await _next(context);
|
|
}
|
|
}
|
|
}
|
|
|