File tree Expand file tree Collapse file tree
src/MemoryPack.AspNetCoreMvcFormatter Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using Microsoft . Net . Http . Headers ;
2+
3+ namespace MemoryPack . AspNetCoreMvcFormatter ;
4+
5+ public static class MediaTypeHeaderValues
6+ {
7+ public static readonly MediaTypeHeaderValue ApplicationMemoryPack =
8+ MediaTypeHeaderValue . Parse ( "application/x-memorypack" ) ;
9+ }
Original file line number Diff line number Diff line change @@ -4,11 +4,9 @@ namespace MemoryPack.AspNetCoreMvcFormatter;
44
55public class MemoryPackInputFormatter : InputFormatter
66{
7- const string ContentType = "application/x-memorypack" ;
8-
97 public MemoryPackInputFormatter ( )
108 {
11- SupportedMediaTypes . Add ( ContentType ) ;
9+ SupportedMediaTypes . Add ( MediaTypeHeaderValues . ApplicationMemoryPack ) ;
1210 }
1311
1412 public override async Task < InputFormatterResult > ReadRequestBodyAsync ( InputFormatterContext context )
Original file line number Diff line number Diff line change 1- using Microsoft . AspNetCore . Mvc . Formatters ;
1+ using System . Net . Mime ;
2+ using Microsoft . AspNetCore . Mvc . Formatters ;
23
34namespace MemoryPack . AspNetCoreMvcFormatter ;
45
56public class MemoryPackOutputFormatter : OutputFormatter
67{
7- const string ContentType = "application/x-memorypack" ;
88 readonly MemoryPackSerializerOptions ? options ;
99 readonly bool checkContentType = false ;
1010
@@ -17,14 +17,14 @@ public MemoryPackOutputFormatter(bool checkContentType = false)
1717 public MemoryPackOutputFormatter ( MemoryPackSerializerOptions options )
1818 {
1919 this . options = options ;
20- SupportedMediaTypes . Add ( ContentType ) ;
20+ SupportedMediaTypes . Add ( MediaTypeHeaderValues . ApplicationMemoryPack ) ;
2121 }
2222
2323 public override bool CanWriteResult ( OutputFormatterCanWriteContext context )
2424 {
2525 if ( checkContentType )
2626 {
27- return ( context . ContentType == ContentType ) ;
27+ return MediaTypeHeaderValues . ApplicationMemoryPack . MatchesMediaType ( context . ContentType ) ;
2828 }
2929 else
3030 {
@@ -34,7 +34,7 @@ public override bool CanWriteResult(OutputFormatterCanWriteContext context)
3434
3535 public override Task WriteResponseBodyAsync ( OutputFormatterWriteContext context )
3636 {
37- context . HttpContext . Response . ContentType = ContentType ;
37+ context . ContentType = MediaTypeHeaderValues . ApplicationMemoryPack . MediaType ;
3838
3939 if ( context . Object == null )
4040 {
You can’t perform that action at this time.
0 commit comments