@@ -23,6 +23,8 @@ namespace JsonApiDotNetCore.Middleware
23
23
/// </summary>
24
24
public sealed class JsonApiMiddleware
25
25
{
26
+ private static readonly MediaTypeHeaderValue _mediaType = MediaTypeHeaderValue . Parse ( HeaderConstants . MediaType ) ;
27
+
26
28
private readonly RequestDelegate _next ;
27
29
28
30
public JsonApiMiddleware ( RequestDelegate next )
@@ -96,7 +98,7 @@ private static async Task<bool> ValidateContentTypeHeaderAsync(HttpContext httpC
96
98
private static async Task < bool > ValidateAcceptHeaderAsync ( HttpContext httpContext , JsonSerializerSettings serializerSettings )
97
99
{
98
100
StringValues acceptHeaders = httpContext . Request . Headers [ "Accept" ] ;
99
- if ( ! acceptHeaders . Any ( ) || acceptHeaders == HeaderConstants . MediaType )
101
+ if ( ! acceptHeaders . Any ( ) )
100
102
{
101
103
return true ;
102
104
}
@@ -105,15 +107,17 @@ private static async Task<bool> ValidateAcceptHeaderAsync(HttpContext httpContex
105
107
106
108
foreach ( var acceptHeader in acceptHeaders )
107
109
{
108
- if ( MediaTypeHeaderValue . TryParse ( acceptHeader , out var headerValue ) )
110
+ if ( MediaTypeWithQualityHeaderValue . TryParse ( acceptHeader , out var headerValue ) )
109
111
{
112
+ headerValue . Quality = null ;
113
+
110
114
if ( headerValue . MediaType == "*/*" || headerValue . MediaType == "application/*" )
111
115
{
112
116
seenCompatibleMediaType = true ;
113
117
break ;
114
118
}
115
119
116
- if ( headerValue . MediaType == HeaderConstants . MediaType && ! headerValue . Parameters . Any ( ) )
120
+ if ( _mediaType . Equals ( headerValue ) )
117
121
{
118
122
seenCompatibleMediaType = true ;
119
123
break ;
@@ -126,7 +130,7 @@ private static async Task<bool> ValidateAcceptHeaderAsync(HttpContext httpContex
126
130
await FlushResponseAsync ( httpContext . Response , serializerSettings , new Error ( HttpStatusCode . NotAcceptable )
127
131
{
128
132
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."
130
134
} ) ;
131
135
return false ;
132
136
}
0 commit comments