Skip to content

Commit 356319b

Browse files
authored
Fix (#139)
1 parent faae2e5 commit 356319b

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [7.0.1] - 2024-06-17
8+
### Fixed
9+
- "Accept" header with multiple values was being mishandled
10+
711
## [7.0.0] - 2023-11-12
812
### Changed
913
- Migrated to `http_interop` v1.
@@ -246,6 +250,7 @@ the Document model.
246250
### Added
247251
- Client: fetch resources, collections, related resources and relationships
248252

253+
[7.0.1]: https://github.com/f3ath/json-api-dart/compare/7.0.0...7.0.1
249254
[7.0.0]: https://github.com/f3ath/json-api-dart/compare/6.0.1...7.0.0
250255
[6.0.1]: https://github.com/f3ath/json-api-dart/compare/6.0.0...6.0.1
251256
[6.0.0]: https://github.com/f3ath/json-api-dart/compare/5.4.0...6.0.0

example/server.dart

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Future<void> main() async {
2323
handler = TryCatchHandler(handler,
2424
onError: ErrorConverter(onError: (e, stack) async {
2525
stderr.writeln(e);
26+
stderr.writeln(stack);
2627
return Response(500,
2728
document: OutboundErrorDocument(
2829
[ErrorObject(title: 'Internal Server Error')]));

lib/src/query/fields.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Fields with MapMixin<String, Iterable<String>> implements QueryEncodable {
1919
static Fields fromUri(Uri uri) =>
2020
Fields(uri.queryParametersAll.map((k, v) => MapEntry(
2121
_regex.firstMatch(k)?.group(1) ?? '',
22-
v.expand((_) => _.split(',')).toList()))
22+
v.expand((it) => it.split(',')).toList()))
2323
..removeWhere((k, v) => k.isEmpty));
2424

2525
static final _regex = RegExp(r'^fields\[(.+)\]$');

lib/src/query/include.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Include with IterableMixin<String> implements QueryEncodable {
1414
}
1515

1616
static Include fromUri(Uri uri) => Include(
17-
uri.queryParametersAll['include']?.expand((_) => _.split(',')) ?? []);
17+
uri.queryParametersAll['include']?.expand((it) => it.split(',')) ?? []);
1818

1919
final _ = <String>[];
2020

lib/src/server/controller_router.dart

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:http_interop/http_interop.dart';
22
import 'package:http_parser/http_parser.dart';
33
import 'package:json_api/http.dart';
44
import 'package:json_api/routing.dart';
5+
import 'package:json_api/src/media_type.dart';
56
import 'package:json_api/src/server/controller.dart';
67
import 'package:json_api/src/server/errors/method_not_allowed.dart';
78
import 'package:json_api/src/server/errors/unacceptable.dart';
@@ -47,16 +48,19 @@ class ControllerRouter implements Handler {
4748

4849
void _validate(Request request) {
4950
final contentType = request.headers.last('Content-Type');
50-
if (contentType != null && !_isValid(MediaType.parse(contentType))) {
51+
if (contentType != null && _isInvalid(MediaType.parse(contentType))) {
5152
throw UnsupportedMediaType();
5253
}
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)) {
5559
throw Unacceptable();
5660
}
5761
}
5862

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
6266
}

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_api
2-
version: 7.0.0
2+
version: 7.0.1
33
homepage: https://github.com/f3ath/json-api-dart
44
description: A framework-agnostic implementations of JSON:API Client and Server. Supports JSON:API v1.0 (https://jsonapi.org)
55
environment:

0 commit comments

Comments
 (0)