[−][src]Struct tide::Request
An HTTP request.
The Request gives endpoints access to basic information about the incoming
request, route parameters, and various ways of accessing the request's body.
Requests also provide extensions, a type map primarily used for low-level communication between middleware and endpoints.
Implementations
impl<State> Request<State>[src]
#[must_use]pub fn method(&self) -> Method[src]
Access the request's HTTP method.
Examples
use tide::Request; let mut app = tide::new(); app.at("/").get(|req: Request<()>| async move { assert_eq!(req.method(), http_types::Method::Get); Ok("") }); app.listen("127.0.0.1:8080").await?;
#[must_use]pub fn url(&self) -> &Url[src]
Access the request's full URI method.
Examples
use tide::Request; let mut app = tide::new(); app.at("/").get(|req: Request<()>| async move { assert_eq!(req.url(), &"/".parse::<tide::http::Url>().unwrap()); Ok("") }); app.listen("127.0.0.1:8080").await?;
#[must_use]pub fn version(&self) -> Option<Version>[src]
Access the request's HTTP version.
Examples
use tide::Request; let mut app = tide::new(); app.at("/").get(|req: Request<()>| async move { assert_eq!(req.version(), Some(http_types::Version::Http1_1)); Ok("") }); app.listen("127.0.0.1:8080").await?;
#[must_use]pub fn peer_addr(&self) -> Option<&str>[src]
Get the peer socket address for the underlying transport, if that information is available for this request.
#[must_use]pub fn local_addr(&self) -> Option<&str>[src]
Get the local socket address for the underlying transport, if that information is available for this request.
#[must_use]pub fn remote(&self) -> Option<&str>[src]
Get the remote address for this request.
This is determined in the following priority:
Forwardedheaderforkey- The first
X-Forwarded-Forheader - Peer address of the transport
#[must_use]pub fn host(&self) -> Option<&str>[src]
Get the destination host for this request.
This is determined in the following priority:
Forwardedheaderhostkey- The first
X-Forwarded-Hostheader Hostheader- URL domain, if any
#[must_use]pub fn content_type(&self) -> Option<Mime>[src]
#[must_use]pub fn header(&self, key: impl Into<HeaderName>) -> Option<&HeaderValues>[src]
Get an HTTP header.
Examples
use tide::Request; let mut app = tide::new(); app.at("/").get(|req: Request<()>| async move { assert_eq!(req.header("X-Forwarded-For").unwrap(), "127.0.0.1"); Ok("") }); app.listen("127.0.0.1:8080").await?;
pub fn header_mut(
&mut self,
name: impl Into<HeaderName>
) -> Option<&mut HeaderValues>[src]
&mut self,
name: impl Into<HeaderName>
) -> Option<&mut HeaderValues>
Get a mutable reference to a header.
pub fn insert_header(
&mut self,
name: impl Into<HeaderName>,
values: impl ToHeaderValues
) -> Option<HeaderValues>[src]
&mut self,
name: impl Into<HeaderName>,
values: impl ToHeaderValues
) -> Option<HeaderValues>
Set an HTTP header.
pub fn append_header(
&mut self,
name: impl Into<HeaderName>,
values: impl ToHeaderValues
)[src]
&mut self,
name: impl Into<HeaderName>,
values: impl ToHeaderValues
)
Append a header to the headers.
Unlike insert this function will not override the contents of a header, but insert a
header if there aren't any. Or else append to the existing list of headers.
pub fn remove_header(
&mut self,
name: impl Into<HeaderName>
) -> Option<HeaderValues>[src]
&mut self,
name: impl Into<HeaderName>
) -> Option<HeaderValues>
Remove a header.
#[must_use]pub fn iter(&self) -> Iter[src]
An iterator visiting all header pairs in arbitrary order.
#[must_use]pub fn iter_mut(&mut self) -> IterMut[src]
An iterator visiting all header pairs in arbitrary order, with mutable references to the values.
#[must_use]pub fn header_names(&self) -> Names[src]
An iterator visiting all header names in arbitrary order.
#[must_use]pub fn header_values(&self) -> Values[src]
An iterator visiting all header values in arbitrary order.
#[must_use]pub fn ext<T: Send + Sync + 'static>(&self) -> Option<&T>[src]
Get a request extension value.
pub fn set_ext<T: Send + Sync + 'static>(&mut self, val: T) -> Option<T>[src]
Set a request extension value.
#[must_use]pub fn state(&self) -> &State[src]
Access application scoped state.
pub fn param<T: FromStr>(&self, key: &str) -> Result<T, T::Err>[src]
Extract and parse a route parameter by name.
Returns the results of parsing the parameter according to the inferred
output type T.
The name should not include the leading : or the trailing * (if
any).
Errors
Yields an Err if the parameter was found but failed to parse as an
instance of type T.
Panics
Panic if key is not a parameter for the route.
pub fn query<T: DeserializeOwned>(&self) -> Result<T>[src]
Get the URL querystring.
pub fn set_body(&mut self, body: impl Into<Body>)[src]
Set the body reader.
pub fn take_body(&mut self) -> Body[src]
Take the request body as a Body.
pub async fn body_bytes<'_>(&'_ mut self) -> Result<Vec<u8>>[src]
Reads the entire request body into a byte buffer.
This method can be called after the body has already been read, but will produce an empty buffer.
Errors
Any I/O error encountered while reading the body is immediately returned
as an Err.
Examples
use tide::Request; let mut app = tide::new(); app.at("/").get(|mut req: Request<()>| async move { let _body: Vec<u8> = req.body_bytes().await.unwrap(); Ok("") }); app.listen("127.0.0.1:8080").await?;
pub async fn body_string<'_>(&'_ mut self) -> Result<String>[src]
Reads the entire request body into a string.
This method can be called after the body has already been read, but will produce an empty buffer.
Errors
Any I/O error encountered while reading the body is immediately returned
as an Err.
If the body cannot be interpreted as valid UTF-8, an Err is returned.
Examples
use tide::Request; let mut app = tide::new(); app.at("/").get(|mut req: Request<()>| async move { let _body: String = req.body_string().await.unwrap(); Ok("") }); app.listen("127.0.0.1:8080").await?;
pub async fn body_json<'_, T: DeserializeOwned>(&'_ mut self) -> Result<T>[src]
Reads and deserialized the entire request body via json.
Errors
Any I/O error encountered while reading the body is immediately returned
as an Err.
If the body cannot be interpreted as valid json for the target type T,
an Err is returned.
pub async fn body_form<'_, T: DeserializeOwned>(&'_ mut self) -> Result<T>[src]
Parse the request body as a form.
#[must_use]pub fn cookie(&self, name: &str) -> Option<Cookie<'static>>[src]
returns a Cookie by name of the cookie.
#[must_use]pub fn len(&self) -> Option<usize>[src]
Get the length of the body stream, if it has been set.
This value is set when passing a fixed-size object into as the body. E.g. a string, or a
buffer. Consumers of this API should check this value to decide whether to use Chunked
encoding, or set the response length.
#[must_use]pub fn is_empty(&self) -> Option<bool>[src]
Returns true if the request has a set body stream length of zero, false otherwise.
Trait Implementations
impl<State> AsMut<Headers> for Request<State>[src]
impl<State> AsMut<Request> for Request<State>[src]
impl<State> AsRef<Headers> for Request<State>[src]
impl<State> AsRef<Request> for Request<State>[src]
impl<State> AsyncRead for Request<State>[src]
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>[src]
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize>>
fn poll_read_vectored(
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize, Error>>[src]
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize, Error>>
impl<State: Debug> Debug for Request<State>[src]
impl<'_, State> Index<&'_ str> for Request<State>[src]
type Output = HeaderValues
The returned type after indexing.
fn index(&self, name: &str) -> &HeaderValues[src]
Returns a reference to the value corresponding to the supplied name.
Panics
Panics if the name is not present in Request.
impl<State> Index<HeaderName> for Request<State>[src]
type Output = HeaderValues
The returned type after indexing.
fn index(&self, name: HeaderName) -> &HeaderValues[src]
Returns a reference to the value corresponding to the supplied name.
Panics
Panics if the name is not present in Request.
impl<State> Into<Request> for Request<State>[src]
impl<State: Send + Sync + 'static> Into<Response> for Request<State>[src]
impl<State> IntoIterator for Request<State>[src]
type Item = (HeaderName, HeaderValues)
The type of the elements being iterated over.
type IntoIter = IntoIter
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter[src]
Returns a iterator of references over the remaining items.
impl<'a, State> IntoIterator for &'a Request<State>[src]
type Item = (&'a HeaderName, &'a HeaderValues)
The type of the elements being iterated over.
type IntoIter = Iter<'a>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter[src]
impl<'a, State> IntoIterator for &'a mut Request<State>[src]
type Item = (&'a HeaderName, &'a mut HeaderValues)
The type of the elements being iterated over.
type IntoIter = IterMut<'a>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter[src]
Auto Trait Implementations
impl<State> !RefUnwindSafe for Request<State>
impl<State> Send for Request<State> where
State: Send + Sync,
State: Send + Sync,
impl<State> Sync for Request<State> where
State: Send + Sync,
State: Send + Sync,
impl<State> Unpin for Request<State>
impl<State> !UnwindSafe for Request<State>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized, [src]
R: AsyncRead + ?Sized,
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: AsyncRead, [src]
R: AsyncRead,
fn read(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self> where
Self: Unpin, [src]
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectored<'a, Self> where
Self: Unpin, [src]
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectored<'a, Self> where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self> where
Self: Unpin, [src]
Self: Unpin,
fn read_to_end(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self> where
Self: Unpin, [src]
Self: Unpin,
fn read_to_string(&'a mut self, buf: &'a mut String) -> ReadToString<'a, Self> where
Self: Unpin, [src]
Self: Unpin,
fn split(self) -> (ReadHalf<Self>, WriteHalf<Self>) where
Self: AsyncWrite, [src]
Self: AsyncWrite,
fn take(self, limit: u64) -> Take<Self>[src]
fn compat(self) -> Compat<Self> where
Self: Unpin, [src]
Self: Unpin,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator, [src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I[src]
impl<T> ReadExt for T where
T: AsyncRead + ?Sized, [src]
T: AsyncRead + ?Sized,
fn read(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self> where
Self: Unpin, [src]
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin, [src]
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
fn read_to_end(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEndFuture<'a, Self> where
Self: Unpin, [src]
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin, [src]
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self> where
Self: Unpin, [src]
Self: Unpin,
fn take(self, limit: u64) -> Take<Self>[src]
fn by_ref(&mut self) -> &mut Self[src]
fn bytes(self) -> Bytes<Self>[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: AsyncRead, [src]
R: AsyncRead,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> Sealed<T> for T where
T: ?Sized,
T: ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,