@@ -2,6 +2,7 @@ import 'package:http_interop/http_interop.dart';
2
2
import 'package:http_parser/http_parser.dart' ;
3
3
import 'package:json_api/http.dart' ;
4
4
import 'package:json_api/routing.dart' ;
5
+ import 'package:json_api/src/media_type.dart' ;
5
6
import 'package:json_api/src/server/controller.dart' ;
6
7
import 'package:json_api/src/server/errors/method_not_allowed.dart' ;
7
8
import 'package:json_api/src/server/errors/unacceptable.dart' ;
@@ -47,16 +48,19 @@ class ControllerRouter implements Handler {
47
48
48
49
void _validate (Request request) {
49
50
final contentType = request.headers.last ('Content-Type' );
50
- if (contentType != null && ! _isValid (MediaType .parse (contentType))) {
51
+ if (contentType != null && _isInvalid (MediaType .parse (contentType))) {
51
52
throw UnsupportedMediaType ();
52
53
}
53
- final accept = request.headers.last ('Accept' );
54
- if (accept != null && ! _isValid (MediaType .parse (accept))) {
54
+ if ((request.headers['Accept' ] ?? [])
55
+ .expand ((it) => it.split (',' ))
56
+ .map ((it) => it.trim ())
57
+ .map (MediaType .parse)
58
+ .any (_isInvalid)) {
55
59
throw Unacceptable ();
56
60
}
57
61
}
58
62
59
- bool _isValid (MediaType mediaType) {
60
- return mediaType.parameters.isEmpty; // TODO: check for ext and profile
61
- }
63
+ bool _isInvalid (MediaType mt) =>
64
+ mt.mimeType == mediaType &&
65
+ mt.parameters.isNotEmpty; // TODO: check for ext and profile
62
66
}
0 commit comments