lazyBody
This commit is contained in:
parent
10a7012987
commit
447aeb833e
3 changed files with 5 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
||||||
# validate
|
# validate
|
||||||
[](https://pub.dartlang.org/packages/angel_validate)
|
[](https://pub.dartlang.org/packages/angel_validate)
|
||||||
[](https://travis-ci.org/angel-dart/validate)
|
[](https://travis-ci.org/angel-dart/validate)
|
||||||
|
|
||||||
[Live Example](https://angel-dart.github.io/validate)
|
[Live Example](https://angel-dart.github.io/validate)
|
||||||
|
|
|
@ -16,7 +16,7 @@ RequestMiddleware autoParseBody(List<String> fields) {
|
||||||
/// Auto-parses numbers in `req.query`.
|
/// Auto-parses numbers in `req.query`.
|
||||||
RequestMiddleware autoParseQuery(List<String> fields) {
|
RequestMiddleware autoParseQuery(List<String> fields) {
|
||||||
return (RequestContext req, res) async {
|
return (RequestContext req, res) async {
|
||||||
(await req.lazyQuery()).addAll(autoParse(req.query, fields));
|
req.query.addAll(autoParse(req.query, fields));
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ RequestMiddleware filterBody(Iterable<String> only) {
|
||||||
/// Filters unwanted data out of `req.query`.
|
/// Filters unwanted data out of `req.query`.
|
||||||
RequestMiddleware filterQuery(Iterable<String> only) {
|
RequestMiddleware filterQuery(Iterable<String> only) {
|
||||||
return (RequestContext req, res) async {
|
return (RequestContext req, res) async {
|
||||||
var filtered = filter(await req.lazyQuery(), only);
|
var filtered = filter(req.query, only);
|
||||||
req.query
|
req.query
|
||||||
..clear()
|
..clear()
|
||||||
..addAll(filtered);
|
..addAll(filtered);
|
||||||
|
@ -48,7 +48,7 @@ RequestMiddleware filterQuery(Iterable<String> only) {
|
||||||
RequestMiddleware validate(Validator validator,
|
RequestMiddleware validate(Validator validator,
|
||||||
{String errorMessage: 'Invalid data.'}) {
|
{String errorMessage: 'Invalid data.'}) {
|
||||||
return (RequestContext req, res) async {
|
return (RequestContext req, res) async {
|
||||||
var result = validator.check(req.body);
|
var result = validator.check(await req.lazyBody());
|
||||||
|
|
||||||
if (result.errors.isNotEmpty) {
|
if (result.errors.isNotEmpty) {
|
||||||
throw new AngelHttpException.badRequest(
|
throw new AngelHttpException.badRequest(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: angel_validate
|
name: angel_validate
|
||||||
description: Cross-platform validation library based on `matcher`.
|
description: Cross-platform validation library based on `matcher`.
|
||||||
version: 1.0.2+3
|
version: 1.0.2+4
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/validate
|
homepage: https://github.com/angel-dart/validate
|
||||||
environment:
|
environment:
|
||||||
|
|
Loading…
Reference in a new issue