1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! # `vld_web::ntex3` — ntex 3 integration for `vld`
//!
//! Provides extractors that validate request data using `vld` schemas:
//!
//! | Extractor | Replaces | Source |
//! |---|---|---|
//! | [`VldJson<T>`] | `ntex::web::types::Json<T>` | JSON request body |
//! | [`VldQuery<T>`] | `ntex::web::types::Query<T>` | URL query parameters |
//! | [`VldPath<T>`] | `ntex::web::types::Path<T>` | URL path parameters |
//! | [`VldForm<T>`] | `ntex::web::types::Form<T>` | URL-encoded form body |
//! | [`VldHeaders<T>`] | manual header extraction | HTTP headers |
//! | [`VldCookie<T>`] | manual cookie parsing | Cookie values |
//!
//! All extractors return **422 Unprocessable Entity** on validation failure
//! or malformed input, and **413 Payload Too Large** when the body exceeds
//! the limit. [`VldJson`] requires a JSON `Content-Type` (`application/json`
//! or `application/*+json`) and [`VldForm`]
//! `application/x-www-form-urlencoded`; anything else is **415 Unsupported
//! Media Type**. See the [error body format](crate::common#error-bodies).
//!
//! Guide: <https://s00d.github.io/vld/integrations/web/ntex> (shared rules
//! for all adapters: <https://s00d.github.io/vld/integrations/web/overview>).
//!
//! # Body limits
//!
//! [`VldJson`] and [`VldForm`] read the body themselves up to
//! [`DEFAULT_BODY_LIMIT`](crate::common::DEFAULT_BODY_LIMIT) (2 MiB); ntex's
//! `JsonConfig` / `PayloadConfig` do not apply. Register [`VldBodyLimit`] as
//! app state to change it: `App::new().state(VldBodyLimit(n))`. Compressed request bodies are decoded only
//! with the `ntex-compress` feature (the limit then applies to the decoded
//! size).
//!
//! # ntex versions
//!
//! This module is ntex 3 (feature `ntex-3`); `vld_web::ntex4` is the same
//! adapter for ntex 4 (feature `ntex-4`). Both can be enabled together.
//! The ntex crate is re-exported as [`ntex`].
//!
//! # Example
//!
//! ```no_run
//! use vld_web::ntex3::ntex::web::HttpResponse;
//! use vld_web::ntex3::{VldJson, VldPath};
//!
//! vld::schema! {
//! #[derive(Debug)]
//! pub struct PathParams {
//! pub id: i64 => vld::number().int().min(1),
//! }
//! }
//!
//! vld::schema! {
//! #[derive(Debug)]
//! pub struct Body {
//! pub name: String => vld::string().min(2),
//! }
//! }
//!
//! async fn handler(
//! path: VldPath<PathParams>,
//! body: VldJson<Body>,
//! ) -> HttpResponse {
//! HttpResponse::Ok().body(format!("id={} name={}", path.id, body.name))
//! }
//!
//! // Inside `HttpServer::new(...)`:
//! // App::new().route("/users/{id}", web::post().to(handler))
//! ```
/// The ntex 3 crate this module is built on.
pub use ntex3 as ntex;
// One implementation, compiled once per ntex major (ARCHITECTURE.md).
pub use *;
/// ntex 3 glue: error rendering and the `FromRequest` impls (forwarding to
/// each extractor's inherent `extract`).