36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
using Microsoft.AspNetCore.Mvc.Formatters;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AdventOfCode.Common
|
|
{
|
|
public class TextPlainInputFormatter : InputFormatter
|
|
{
|
|
private const string ContentType = "text/plain";
|
|
|
|
public TextPlainInputFormatter()
|
|
{
|
|
SupportedMediaTypes.Add(ContentType);
|
|
}
|
|
|
|
public override async Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context)
|
|
{
|
|
var request = context.HttpContext.Request;
|
|
using (var reader = new StreamReader(request.Body))
|
|
{
|
|
var content = await reader.ReadToEndAsync();
|
|
return await InputFormatterResult.SuccessAsync(content);
|
|
}
|
|
}
|
|
|
|
public override bool CanRead(InputFormatterContext context)
|
|
{
|
|
var contentType = context.HttpContext.Request.ContentType;
|
|
return contentType.StartsWith(ContentType);
|
|
}
|
|
}
|
|
}
|