Skip to main content

IHttpRequest

Trait IHttpRequest 

Source
pub trait IHttpRequest: Send {
Show 15 methods // Required methods fn method(&self) -> &str; fn path(&self) -> &str; fn header(&self, name: &str) -> Option<&str>; fn query(&self) -> &HashMap<String, String>; fn route_params(&self) -> &HashMap<String, String>; fn route_params_mut(&mut self) -> &mut HashMap<String, String>; fn route_pattern(&self) -> Option<&str>; fn route_pattern_mut(&mut self) -> &mut Option<String>; fn body_bytes<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; // Provided methods fn remote_addr(&self) -> Option<SocketAddr> { ... } fn query_all(&self) -> Option<&HashMap<String, Vec<String>>> { ... } fn body_text<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn content_type(&self) -> Option<&str> { ... } fn is_multipart(&self) -> bool { ... } fn multipart<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Arc<MultipartForm>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... }
}
Expand description

HTTP request abstraction.

Analogous to ASP.NET Core’s HttpRequest.

Methods are non-generic to maintain dyn-compatibility. Use serde_json::from_slice on the raw body bytes for JSON deserialization.

Required Methods§

Source

fn method(&self) -> &str

Source

fn path(&self) -> &str

Source

fn header(&self, name: &str) -> Option<&str>

Source

fn query(&self) -> &HashMap<String, String>

Source

fn route_params(&self) -> &HashMap<String, String>

Source

fn route_params_mut(&mut self) -> &mut HashMap<String, String>

Source

fn route_pattern(&self) -> Option<&str>

The original route pattern that was matched (e.g., "/api/users/{id}"). Set by the router after successful route matching.

Source

fn route_pattern_mut(&mut self) -> &mut Option<String>

Source

fn body_bytes<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Return the raw request body bytes.

The body can only be read once; a second call reports an error rather than silently returning an empty body.

Provided Methods§

Source

fn remote_addr(&self) -> Option<SocketAddr>

The peer address of the client connection, when the host exposes it.

Rate limiting and audit code use this. The default reports None so that test contexts and alternative hosts keep compiling; a None peer must never be treated as “the same client as everyone else”.

Source

fn query_all(&self) -> Option<&HashMap<String, Vec<String>>>

Every value per query key, in the order they appeared.

?id=1&id=2 yields two values for id, which is what Vec<T> query fields bind from. The default implementation reports no multi-value support, so a host that does not override this still binds the single-value IHttpRequest::query view.

Source

fn body_text<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Return the request body as a UTF-8 string.

Source

fn content_type(&self) -> Option<&str>

The request’s media type, without parameters (e.g. "multipart/form-data").

Comparison is case-insensitive; see IHttpRequest::is_multipart.

Source

fn is_multipart(&self) -> bool

Whether the request declares Content-Type: multipart/form-data.

Source

fn multipart<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Arc<MultipartForm>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Parse the request body as multipart/form-data.

The parsed form is cached on the request, so repeated calls are cheap and spooled uploads stay alive until the request is finished. Call crate::form::FormFile::save_as from your handler to keep a file.

The default implementation reports the request as unsupported; the rust-webx HTTP host provides the real parser.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§