mirror of
https://github.com/fergalmoran/podnoms.git
synced 2026-01-12 11:36:43 +00:00
26 lines
976 B
C#
26 lines
976 B
C#
using System;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
|
|
|
namespace PodNoms.Api.Services.Push.Formatters {
|
|
internal class TextPlainInputFormatter : TextInputFormatter {
|
|
public TextPlainInputFormatter() {
|
|
SupportedMediaTypes.Add("text/plain");
|
|
SupportedEncodings.Add(UTF8EncodingWithoutBOM);
|
|
SupportedEncodings.Add(UTF16EncodingLittleEndian);
|
|
}
|
|
|
|
protected override bool CanReadType(Type type) {
|
|
return type == typeof(string);
|
|
}
|
|
|
|
public override async Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding) {
|
|
string data = null;
|
|
using (var streamReader = context.ReaderFactory(context.HttpContext.Request.Body, encoding)) {
|
|
data = await streamReader.ReadToEndAsync();
|
|
}
|
|
return InputFormatterResult.Success(data);
|
|
}
|
|
}
|
|
} |