vld_web/rama/extract/
mod.rs1mod cookie;
2mod form;
3mod headers;
4mod json;
5mod path;
6mod query;
7
8pub use cookie::VldCookie;
9pub use form::VldForm;
10pub use headers::VldHeaders;
11pub use json::VldJson;
12pub use path::VldPath;
13pub use query::VldQuery;
14
15use crate::rama::VldBodyLimit;
16use crate::rama::rejection::VldRejection;
17
18use crate::common::DEFAULT_BODY_LIMIT;
19use rama::http::Body;
20use rama::http::body::util::BodyExt;
21use rama::http::request::Parts;
22
23crate::impl_deref!(VldJson, VldQuery, VldPath, VldForm, VldHeaders, VldCookie);
24
25fn body_limit(parts: &Parts) -> usize {
27 parts
28 .extensions
29 .get_ref::<VldBodyLimit>()
30 .map_or(DEFAULT_BODY_LIMIT, |l| l.0)
31}
32
33async fn read_body(body: Body, limit: usize) -> Result<rama::bytes::Bytes, VldRejection> {
34 Ok(body
35 .limited(limit)
36 .collect()
37 .await
38 .map_err(|e| VldRejection::from_body_error(&e))?
39 .to_bytes())
40}