File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
JsonApiDotNetCore/Middleware Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -28,15 +28,23 @@ public async Task Invoke(HttpContext context)
2828 {
2929 _logger . LogInformation ( "Passing request to JsonApiService: " + context . Request . Path ) ;
3030
31- var wasHandled = _jsonApiService . HandleJsonApiRoute ( context , _serviceProvider ) ;
31+ if ( context . Request . ContentType == "application/vnd.api+json" ) {
32+ var wasHandled = _jsonApiService . HandleJsonApiRoute ( context , _serviceProvider ) ;
33+ }
34+ else
35+ {
36+ _logger . LogInformation ( "Content-Type invalid for JsonAPI" ) ;
3237
33- if ( ! wasHandled ) {
34- _logger . LogInformation ( "Request not handled by JsonApiService. Middleware pipeline continued." ) ;
3538 await _next . Invoke ( context ) ;
39+
40+ RespondUnsupportedMediaType ( context ) ;
3641 }
37- else {
38- _logger . LogInformation ( "Request handled by JsonApiService. Middleware pipeline terminated." ) ;
39- }
42+ }
43+
44+ private void RespondUnsupportedMediaType ( HttpContext context )
45+ {
46+ context . Response . StatusCode = 415 ;
47+ context . Response . Body . Flush ( ) ;
4048 }
4149 }
4250}
You can’t perform that action at this time.
0 commit comments