decode+deserialize body
This commit is contained in:
parent
2fdfb848f0
commit
91bc517b1f
2 changed files with 13 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
# 2.0.5
|
||||
* 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
|
||||
* Prepare for Dart SDK change to `Stream<List<int>>` that are now
|
||||
|
|
|
@ -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.
|
||||
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.
|
||||
Future<void> parseBody({Encoding encoding = utf8}) async {
|
||||
if (contentType == null) {
|
||||
|
|
Loading…
Reference in a new issue