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
use ;
use Request;
use crateRuntimeError;
use DeserializeOwned;
/// Validate the request body as JSON of type `T`.
///
/// Requests with an empty body pass through without validation (e.g. GET).
/// Invalid JSON becomes a malformed-body rejection, answered by the router's
/// configured rejection mapper or by the built-in `400`.
///
/// A validation failure leaves as the parser's own `RuntimeError`, not as a
/// response: the router's rejection boundary classifies it as a malformed body
/// and decides what the peer is told, so this frame never rebuilds that
/// decision from the parser's text.
///
/// The body is parsed twice: once here for validation and once in the handler
/// via `req.json()`. Both parse the same `Bytes` buffer, so the cost is a
/// second deserialize with no allocation and no second decode. A type-erased
/// cache would eliminate the second parse but adds `Any + Send + Sync`
/// complexity for marginal gain.
+ Send + Sync + 'static
/// Whether this body is the representation the route declared.
///
/// An empty body carries no representation to check, so it passes: a `GET`
/// through this frame is not a malformed `POST`.
///
/// Emptiness is read off the raw bytes. Asking the text view instead decoded
/// the whole body to answer a length question, and cached a lossy copy of every
/// body that is not UTF-8.