diff --git a/.idea/runConfigurations/All_Tests.xml b/.idea/runConfigurations/All_Tests.xml
index c753608c..dcd3564d 100644
--- a/.idea/runConfigurations/All_Tests.xml
+++ b/.idea/runConfigurations/All_Tests.xml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 8b7d24a9..7fda60b9 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,14 +1,15 @@
-
-
+
+
+
+
-
-
+
-
+
@@ -32,20 +33,48 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -55,8 +84,40 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -65,27 +126,17 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
+
@@ -176,16 +227,18 @@
-
-
-
+
+
+
+
+
@@ -219,7 +272,6 @@
-
@@ -316,6 +368,7 @@
+
@@ -344,7 +397,7 @@
-
+
@@ -425,6 +478,11 @@
false
+
+
+
+
+
@@ -462,23 +520,24 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -516,7 +575,8 @@
-
+
+
1481237183504
@@ -672,27 +732,34 @@
1498960583872
-
+
+ 1499619046675
+
+
+
+ 1499619046675
+
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
@@ -708,7 +775,7 @@
-
+
@@ -721,13 +788,14 @@
-
+
-
-
+
+
+
@@ -736,14 +804,12 @@
-
-
@@ -775,35 +841,15 @@
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -938,16 +984,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1032,13 +1068,6 @@
-
-
-
-
-
-
-
@@ -1081,50 +1110,9 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -1132,19 +1120,111 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 00000000..f55f08bc
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,3 @@
+# 1.0.7
+Added an `accepts` method to `RequestContext`. It's now a lot easier to tell which content types the
+user accepts via the `Accept` header.
\ No newline at end of file
diff --git a/lib/src/http/request_context.dart b/lib/src/http/request_context.dart
index 34f31106..73dcbd5e 100644
--- a/lib/src/http/request_context.dart
+++ b/lib/src/http/request_context.dart
@@ -8,6 +8,8 @@ import 'server.dart' show Angel;
/// A convenience wrapper around an incoming HTTP request.
class RequestContext extends Extensible {
+ String _acceptHeaderCache;
+ bool _acceptsAllCache;
BodyParseResult _body;
ContentType _contentType;
HttpRequest _io;
@@ -187,6 +189,36 @@ class RequestContext extends Extensible {
injections[type] = value;
}
+ /// Returns `true` if the client's `Accept` header indicates that the given [contentType] is considered a valid response.
+ ///
+ /// You cannot provide a `null` [contentType].
+ /// If the `Accept` header's value is `*/*`, this method will always return `true`.
+ ///
+ /// [contentType] can be either of the following:
+ /// * A [ContentType], in which case the `Accept` header will be compared against its `mimeType` property.
+ /// * Any other Dart value, in which case the `Accept` header will be compared against the result of a `toString()` call.
+ bool accepts(contentType) {
+ var contentTypeString = contentType is ContentType
+ ? contentType.mimeType
+ : contentType?.toString();
+
+ if (contentTypeString == null)
+ throw new ArgumentError(
+ 'RequestContext.accepts expects the `contentType` parameter to NOT be null.');
+
+ _acceptHeaderCache ??= headers.value(HttpHeaders.ACCEPT);
+
+ if (_acceptHeaderCache == null)
+ return false;
+ else if (_acceptHeaderCache.contains('*/*'))
+ return true;
+ else
+ return _acceptHeaderCache.contains(contentTypeString);
+ }
+
+ /// Returns as `true` if the client's `Accept` header indicates that it will accept any response content type.
+ bool get acceptsAll => _acceptsAllCache ??= accepts('*/*');
+
/// Retrieves the request body if it has already been parsed, or lazy-parses it before returning the body.
Future