@@ -23,6 +23,8 @@ namespace JsonApiDotNetCore.Middleware
2323 /// </summary>
2424 public sealed class JsonApiMiddleware
2525 {
26+ private static readonly MediaTypeHeaderValue _mediaType = MediaTypeHeaderValue . Parse ( HeaderConstants . MediaType ) ;
27+
2628 private readonly RequestDelegate _next ;
2729
2830 public JsonApiMiddleware ( RequestDelegate next )
@@ -96,7 +98,7 @@ private static async Task<bool> ValidateContentTypeHeaderAsync(HttpContext httpC
9698 private static async Task < bool > ValidateAcceptHeaderAsync ( HttpContext httpContext , JsonSerializerSettings serializerSettings )
9799 {
98100 StringValues acceptHeaders = httpContext . Request . Headers [ "Accept" ] ;
99- if ( ! acceptHeaders . Any ( ) || acceptHeaders == HeaderConstants . MediaType )
101+ if ( ! acceptHeaders . Any ( ) )
100102 {
101103 return true ;
102104 }
@@ -105,15 +107,17 @@ private static async Task<bool> ValidateAcceptHeaderAsync(HttpContext httpContex
105107
106108 foreach ( var acceptHeader in acceptHeaders )
107109 {
108- if ( MediaTypeHeaderValue . TryParse ( acceptHeader , out var headerValue ) )
110+ if ( MediaTypeWithQualityHeaderValue . TryParse ( acceptHeader , out var headerValue ) )
109111 {
112+ headerValue . Quality = null ;
113+
110114 if ( headerValue . MediaType == "*/*" || headerValue . MediaType == "application/*" )
111115 {
112116 seenCompatibleMediaType = true ;
113117 break ;
114118 }
115119
116- if ( headerValue . MediaType == HeaderConstants . MediaType && ! headerValue . Parameters . Any ( ) )
120+ if ( _mediaType . Equals ( headerValue ) )
117121 {
118122 seenCompatibleMediaType = true ;
119123 break ;
@@ -126,7 +130,7 @@ private static async Task<bool> ValidateAcceptHeaderAsync(HttpContext httpContex
126130 await FlushResponseAsync ( httpContext . Response , serializerSettings , new Error ( HttpStatusCode . NotAcceptable )
127131 {
128132 Title = "The specified Accept header value does not contain any supported media types." ,
129- Detail = $ "Please include '{ HeaderConstants . MediaType } ' in the Accept header values."
133+ Detail = $ "Please include '{ _mediaType } ' in the Accept header values."
130134 } ) ;
131135 return false ;
132136 }
0 commit comments