pub struct Request {
pub method: Method,
pub uri: Uri,
pub headers: HeaderMap,
pub body: Bytes,
pub params: Params,
pub query: Query,
pub extensions: Extensions,
pub remote_addr: Option<SocketAddr>,
pub matched_path: Option<Arc<str>>,
/* private fields */
}Expand description
HTTP Request wrapper
Fields§
§method: Method§uri: Uri§headers: HeaderMap§body: Bytes§params: Params§query: Query§extensions: ExtensionsTyped per-request data; middleware can attach values for handlers (authenticated user, request id, …).
remote_addr: Option<SocketAddr>Address of the connected peer (the proxy when behind one)
matched_path: Option<Arc<str>>The route pattern that matched, e.g. /users/{id}; None when no route
matched. Use it, not the raw path, as a metrics label or log field: it
stays the same for every id.
Implementations§
Source§impl Request
impl Request
Sourcepub fn multipart(&self) -> Result<Multipart>
pub fn multipart(&self) -> Result<Multipart>
Parse a multipart/form-data body with the default MultipartLimits
415 for other content types, 400 for malformed bodies.
pub fn multipart_with(&self, limits: &MultipartLimits) -> Result<Multipart>
Source§impl Request
impl Request
Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
Id assigned by RequestIdLayer, if installed
Source§impl Request
impl Request
pub fn new(method: Method, uri: Uri, headers: HeaderMap, body: Bytes) -> Self
Sourcepub fn state<T: Send + Sync + 'static>(&self) -> Result<&T>
pub fn state<T: Send + Sync + 'static>(&self) -> Result<&T>
Shared application state registered with App::state
Answers 500 when no value of type T was registered: that is a
programming error, not something the client can fix.
Sourcepub fn shutdown_signal(&self) -> Shutdown
pub fn shutdown_signal(&self) -> Shutdown
Signal that fires when the server begins shutting down
Long-lived handlers (SSE streams, polling loops) select on it to end
promptly: tokio::select! { _ = req.shutdown_signal().wait() => break, ... }.
Sourcepub fn try_state<T: Send + Sync + 'static>(&self) -> Option<&T>
pub fn try_state<T: Send + Sync + 'static>(&self) -> Option<&T>
Like Request::state, None when the type is not registered
Get cookies from the request
Sourcepub fn form<T: DeserializeOwned>(&self) -> Result<T>
pub fn form<T: DeserializeOwned>(&self) -> Result<T>
Parse an application/x-www-form-urlencoded body into a struct
Answers 415 for other content types and 400 for values that do not
fit the target type.
Sourcepub fn form_data(&self) -> Result<Query>
pub fn form_data(&self) -> Result<Query>
The same body as decoded key/value access (+ and %XX decoded)
Sourcepub fn json<T: DeserializeOwned>(&self) -> Result<T>
pub fn json<T: DeserializeOwned>(&self) -> Result<T>
Parse JSON body