decode+deserialize body

This commit is contained in:
thosakwe 2019-07-17 15:05:51 -04:00
parent 2fdfb848f0
commit 91bc517b1f
2 changed files with 13 additions and 1 deletions

View file

@ -1,6 +1,7 @@
# 2.0.5 # 2.0.5
* Add `allowHttp1` to `AngelHttp2` constructors. https://github.com/angel-dart/angel/issues/108 * Add `allowHttp1` to `AngelHttp2` constructors. https://github.com/angel-dart/angel/issues/108
* * Add `deserializeBody` and `decodeBody` to `RequestContext`. https://github.com/angel-dart/angel/issues/109
* Add `HostnameRouter`, which allows for routing based on hostname. https://github.com/angel-dart/angel/issues/110
# 2.0.4 # 2.0.4
* Prepare for Dart SDK change to `Stream<List<int>>` that are now * Prepare for Dart SDK change to `Stream<List<int>>` that are now

View file

@ -221,6 +221,17 @@ abstract class RequestContext<RawRequest> {
/// Returns as `true` if the client's `Accept` header indicates that it will accept any response content type. /// Returns as `true` if the client's `Accept` header indicates that it will accept any response content type.
bool get acceptsAll => _acceptsAllCache ??= accepts('*/*'); bool get acceptsAll => _acceptsAllCache ??= accepts('*/*');
/// Shorthand for deserializing a body.
Future<T> deserializeBody<T>(FutureOr<T> Function(Map) f,
{Encoding encoding = utf8}) async {
await parseBody(encoding: encoding);
return await f(bodyAsMap);
}
/// Shorthand for decoding a body.
Future<T> decodeBody<T>(Codec<T, Map> codec, {Encoding encoding = utf8}) =>
deserializeBody(codec.decode, encoding: encoding);
/// Manually parses the request body, if it has not already been parsed. /// Manually parses the request body, if it has not already been parsed.
Future<void> parseBody({Encoding encoding = utf8}) async { Future<void> parseBody({Encoding encoding = utf8}) async {
if (contentType == null) { if (contentType == null) {