aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Formatters
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-02-12 22:39:57 +0800
committerGitHub <noreply@github.com>2021-02-12 22:39:57 +0800
commitc3d0a5f88de0fbdf6bc584548832017087ab1248 (patch)
treec1c992987263897fb1c091c5129c6d1f1e64073d /BackEnd/Timeline/Formatters
parente232e31de839dc0c0de691c5856f29dcb92cf0fc (diff)
parent5849d34d9fcf1ccfb7fe5cc0842765129f7198b4 (diff)
downloadtimeline-c3d0a5f88de0fbdf6bc584548832017087ab1248.tar.gz
timeline-c3d0a5f88de0fbdf6bc584548832017087ab1248.tar.bz2
timeline-c3d0a5f88de0fbdf6bc584548832017087ab1248.zip
Merge pull request #267 from crupest/backend
春节大换血 Spring festival big change.
Diffstat (limited to 'BackEnd/Timeline/Formatters')
-rw-r--r--BackEnd/Timeline/Formatters/ByteDataInputFormatter.cs (renamed from BackEnd/Timeline/Formatters/BytesInputFormatter.cs)25
1 files changed, 16 insertions, 9 deletions
diff --git a/BackEnd/Timeline/Formatters/BytesInputFormatter.cs b/BackEnd/Timeline/Formatters/ByteDataInputFormatter.cs
index ac6537c9..49f8221a 100644
--- a/BackEnd/Timeline/Formatters/BytesInputFormatter.cs
+++ b/BackEnd/Timeline/Formatters/ByteDataInputFormatter.cs
@@ -1,7 +1,6 @@
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
-using Microsoft.Net.Http.Headers;
using System;
using System.Threading.Tasks;
using Timeline.Models;
@@ -9,19 +8,21 @@ using Timeline.Models;
namespace Timeline.Formatters
{
/// <summary>
- /// Formatter that reads body as bytes.
+ /// Formatter that reads body as byte data.
/// </summary>
- public class BytesInputFormatter : InputFormatter
+ public class ByteDataInputFormatter : InputFormatter
{
/// <summary>
///
/// </summary>
- public BytesInputFormatter()
+ public ByteDataInputFormatter()
{
- SupportedMediaTypes.Add(new MediaTypeHeaderValue("image/png"));
- SupportedMediaTypes.Add(new MediaTypeHeaderValue("image/jpeg"));
- SupportedMediaTypes.Add(new MediaTypeHeaderValue("image/gif"));
- SupportedMediaTypes.Add(new MediaTypeHeaderValue("image/webp"));
+ SupportedMediaTypes.Add(MimeTypes.ImagePng);
+ SupportedMediaTypes.Add(MimeTypes.ImageJpeg);
+ SupportedMediaTypes.Add(MimeTypes.ImageGif);
+ SupportedMediaTypes.Add(MimeTypes.ImageWebp);
+ SupportedMediaTypes.Add(MimeTypes.TextPlain);
+ SupportedMediaTypes.Add(MimeTypes.TextMarkdown);
}
/// <inheritdoc/>
@@ -41,7 +42,13 @@ namespace Timeline.Formatters
var request = context.HttpContext.Request;
var contentLength = request.ContentLength;
- var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<BytesInputFormatter>>();
+ var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<ByteDataInputFormatter>>();
+
+ if (request.ContentType is null)
+ {
+ logger.LogInformation("Failed to read body as bytes. Content-Type is not set.");
+ return await InputFormatterResult.FailureAsync();
+ }
if (contentLength == null)
{