diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b9f24d1..22e0d51e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.0.0 +* Finish update for Angel 2. + # 2.0.0-alpha.1 * Update for Angel 2. diff --git a/lib/server.dart b/lib/server.dart index 6b7420bc..4e914176 100644 --- a/lib/server.dart +++ b/lib/server.dart @@ -12,7 +12,8 @@ export 'angel_validate.dart'; /// Auto-parses numbers in `req.body`. RequestHandler autoParseBody(List fields) { return (RequestContext req, res) async { - (await req.parseBody()).addAll(autoParse(await req.parseBody(), fields)); + var body = await req.parseBody(); + body.addAll(autoParse(body, fields)); return true; }; } @@ -20,7 +21,8 @@ RequestHandler autoParseBody(List fields) { /// Auto-parses numbers in `req.query`. RequestHandler autoParseQuery(List fields) { return (RequestContext req, res) async { - (await req.parseQuery()).addAll(autoParse(await req.parseQuery(), fields)); + var query = new Map.from(await req.parseQuery()); + (await req.parseQuery()).addAll(autoParse(query, fields)); return true; }; } @@ -28,8 +30,9 @@ RequestHandler autoParseQuery(List fields) { /// Filters unwanted data out of `req.body`. RequestHandler filterBody(Iterable only) { return (RequestContext req, res) async { - var filtered = filter(await req.parseBody(), only); - (await req.parseBody()) + var body = await req.parseBody(); + var filtered = filter(body, only); + body ..clear() ..addAll(filtered); return true; @@ -41,7 +44,7 @@ RequestHandler filterQuery(Iterable only) { return (RequestContext req, res) async { var query = await req.parseQuery(); var filtered = filter(query, only); - query + (await req.parseQuery()) ..clear() ..addAll(filtered); return true; @@ -53,15 +56,16 @@ RequestHandler filterQuery(Iterable only) { RequestHandler validate(Validator validator, {String errorMessage: 'Invalid data.'}) { return (RequestContext req, res) async { + var body = await req.parseBody(); var result = - await asyncApplyValidator(validator, await req.parseBody(), req.app); + await asyncApplyValidator(validator, body, req.app); if (result.errors.isNotEmpty) { throw new AngelHttpException.badRequest( message: errorMessage, errors: result.errors); } - (await req.parseBody()) + body ..clear() ..addAll(result.data); @@ -74,8 +78,9 @@ RequestHandler validate(Validator validator, RequestHandler validateQuery(Validator validator, {String errorMessage: 'Invalid data.'}) { return (RequestContext req, res) async { + var query = await req.parseQuery(); var result = - await asyncApplyValidator(validator, await req.parseQuery(), req.app); + await asyncApplyValidator(validator, query, req.app); if (result.errors.isNotEmpty) { throw new AngelHttpException.badRequest(