-
-
Notifications
You must be signed in to change notification settings - Fork 673
/
MessagePackInputFormatter.cs
33 lines (27 loc) · 1.19 KB
/
MessagePackInputFormatter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Formatters;
namespace MessagePack.AspNetCoreMvcFormatter
{
public class MessagePackInputFormatter : InputFormatter
{
private const string ContentType = "application/x-msgpack";
private readonly MessagePackSerializerOptions? options;
public MessagePackInputFormatter()
: this(null)
{
}
public MessagePackInputFormatter(MessagePackSerializerOptions? options)
{
this.options = options;
SupportedMediaTypes.Add(ContentType);
}
public override async Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context)
{
var request = context.HttpContext.Request;
var result = await MessagePackSerializer.DeserializeAsync(context.ModelType, request.Body, this.options, context.HttpContext.RequestAborted).ConfigureAwait(false);
return await InputFormatterResult.SuccessAsync(result).ConfigureAwait(false);
}
}
}