Skip to content

Commit

Permalink
Fix (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
f3ath authored Jun 18, 2024
1 parent faae2e5 commit 356319b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [7.0.1] - 2024-06-17
### Fixed
- "Accept" header with multiple values was being mishandled

## [7.0.0] - 2023-11-12
### Changed
- Migrated to `http_interop` v1.
Expand Down Expand Up @@ -246,6 +250,7 @@ the Document model.
### Added
- Client: fetch resources, collections, related resources and relationships

[7.0.1]: https://github.com/f3ath/json-api-dart/compare/7.0.0...7.0.1
[7.0.0]: https://github.com/f3ath/json-api-dart/compare/6.0.1...7.0.0
[6.0.1]: https://github.com/f3ath/json-api-dart/compare/6.0.0...6.0.1
[6.0.0]: https://github.com/f3ath/json-api-dart/compare/5.4.0...6.0.0
Expand Down
1 change: 1 addition & 0 deletions example/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Future<void> main() async {
handler = TryCatchHandler(handler,
onError: ErrorConverter(onError: (e, stack) async {
stderr.writeln(e);
stderr.writeln(stack);
return Response(500,
document: OutboundErrorDocument(
[ErrorObject(title: 'Internal Server Error')]));
Expand Down
2 changes: 1 addition & 1 deletion lib/src/query/fields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Fields with MapMixin<String, Iterable<String>> implements QueryEncodable {
static Fields fromUri(Uri uri) =>
Fields(uri.queryParametersAll.map((k, v) => MapEntry(
_regex.firstMatch(k)?.group(1) ?? '',
v.expand((_) => _.split(',')).toList()))
v.expand((it) => it.split(',')).toList()))
..removeWhere((k, v) => k.isEmpty));

static final _regex = RegExp(r'^fields\[(.+)\]$');
Expand Down
2 changes: 1 addition & 1 deletion lib/src/query/include.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Include with IterableMixin<String> implements QueryEncodable {
}

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

final _ = <String>[];

Expand Down
16 changes: 10 additions & 6 deletions lib/src/server/controller_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:http_interop/http_interop.dart';
import 'package:http_parser/http_parser.dart';
import 'package:json_api/http.dart';
import 'package:json_api/routing.dart';
import 'package:json_api/src/media_type.dart';
import 'package:json_api/src/server/controller.dart';
import 'package:json_api/src/server/errors/method_not_allowed.dart';
import 'package:json_api/src/server/errors/unacceptable.dart';
Expand Down Expand Up @@ -47,16 +48,19 @@ class ControllerRouter implements Handler {

void _validate(Request request) {
final contentType = request.headers.last('Content-Type');
if (contentType != null && !_isValid(MediaType.parse(contentType))) {
if (contentType != null && _isInvalid(MediaType.parse(contentType))) {
throw UnsupportedMediaType();
}
final accept = request.headers.last('Accept');
if (accept != null && !_isValid(MediaType.parse(accept))) {
if ((request.headers['Accept'] ?? [])
.expand((it) => it.split(','))
.map((it) => it.trim())
.map(MediaType.parse)
.any(_isInvalid)) {
throw Unacceptable();
}
}

bool _isValid(MediaType mediaType) {
return mediaType.parameters.isEmpty; // TODO: check for ext and profile
}
bool _isInvalid(MediaType mt) =>
mt.mimeType == mediaType &&
mt.parameters.isNotEmpty; // TODO: check for ext and profile
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json_api
version: 7.0.0
version: 7.0.1
homepage: https://github.com/f3ath/json-api-dart
description: A framework-agnostic implementations of JSON:API Client and Server. Supports JSON:API v1.0 (https://jsonapi.org)
environment:
Expand Down

0 comments on commit 356319b

Please sign in to comment.