pub struct Request { /* private fields */ }Expand description
Handler-facing HTTP request. Owns all data.
Implementations§
Source§impl Request
impl Request
Sourcepub fn is_head(&self) -> bool
pub fn is_head(&self) -> bool
True when the original request method is HEAD.
Handlers can check this to skip expensive body construction. The runtime strips the body automatically for HEAD responses, but this method lets handlers avoid building it in the first place.
Sourcepub fn headers(&self) -> impl Iterator<Item = (&str, &str)> + '_
pub fn headers(&self) -> impl Iterator<Item = (&str, &str)> + '_
Iterate over all request headers as (name, value) pairs.
Invalid header values are yielded as empty strings.
Sourcepub fn header(&self, name: &str) -> Option<&str>
pub fn header(&self, name: &str) -> Option<&str>
Return the first header value matching the given name (case-insensitive).
Uses hyper’s O(1) hash lookup — no linear scan.
Sourcepub fn remote_addr(&self) -> Option<IpAddr>
pub fn remote_addr(&self) -> Option<IpAddr>
Return the remote IP address of the connecting client, if available.
Sourcepub fn body(&self) -> &str
pub fn body(&self) -> &str
Return the request body as text.
Invalid UTF-8 is decoded lossily on first access and cached.
Sourcepub fn body_bytes(&self) -> &[u8] ⓘ
pub fn body_bytes(&self) -> &[u8] ⓘ
Return the raw body bytes.
Sourcepub fn json<T: DeserializeOwned>(&self) -> Result<T, RuntimeError>
pub fn json<T: DeserializeOwned>(&self) -> Result<T, RuntimeError>
Deserialize the request body as JSON.
Sourcepub fn multipart(&self) -> Result<MultipartReader, RuntimeError>
pub fn multipart(&self) -> Result<MultipartReader, RuntimeError>
Parse the request body as multipart/form-data.
Returns a MultipartReader that provides access to all parts.
Fails with BadRequest if the Content-Type is not multipart/form-data.
Sourcepub fn query(&self, name: &str) -> Option<&str>
pub fn query(&self, name: &str) -> Option<&str>
Return the first query parameter value for the given key, or None.
Sourcepub fn query_all<'a>(
&'a self,
name: &'a str,
) -> impl Iterator<Item = &'a str> + 'a
pub fn query_all<'a>( &'a self, name: &'a str, ) -> impl Iterator<Item = &'a str> + 'a
Return an iterator over all query parameter values for the given key.
Sourcepub fn form(&self, name: &str) -> Option<&str>
pub fn form(&self, name: &str) -> Option<&str>
Return the first form field value for the given key, or None.
Lazily parses the request body as application/x-www-form-urlencoded.
Return the value of a cookie by name, or None if not present.
Lazily parses the Cookie header on first access.
Iterate over all cookie name-value pairs.
Lazily parses the Cookie header on first access.
Sourcepub fn builder() -> RequestBuilder
pub fn builder() -> RequestBuilder
Create a RequestBuilder for constructing test requests.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Request
impl RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl UnsafeUnpin for Request
impl UnwindSafe for Request
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request