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>,
/* 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)
Implementations§
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 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
Auto Trait Implementations§
impl !Freeze for Request
impl !RefUnwindSafe for Request
impl !Sync for Request
impl !UnwindSafe for Request
impl Send for Request
impl Unpin for Request
impl UnsafeUnpin for Request
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more