Skip to main content

IHttpRequest

Trait IHttpRequest 

Source
pub trait IHttpRequest: Send {
Show 14 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>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, Self: 'async_trait; // Provided methods 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, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, Self: '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>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, Self: '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>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: '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 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, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: '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>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: '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§