pub struct HttpRequest {
pub method: HttpMethod,
pub uri: Uri,
pub path: String,
pub headers: HeaderMap,
pub query_params: HashMap<String, String>,
pub path_params: HashMap<String, String>,
pub body: Option<Vec<u8>>,
pub content_type: Option<ContentType>,
pub remote_addr: Option<String>,
}Expand description
HTTP request type wrapping Axum’s request with additional metadata.
This type provides a clean interface for working with HTTP requests in StreamWeave pipelines. It extracts and provides easy access to request metadata like method, path, headers, and query parameters.
§Example
use streamweave::http_server::HttpRequest;
use axum::extract::Request;
async fn handle_request(axum_request: Request) -> HttpRequest {
HttpRequest::from_axum_request(axum_request).await
}Fields§
§method: HttpMethodHTTP method (GET, POST, etc.)
uri: UriRequest URI/path
path: StringRequest path as string
headers: HeaderMapHTTP headers
query_params: HashMap<String, String>Query parameters parsed from the URI
path_params: HashMap<String, String>Path parameters (extracted from route patterns)
body: Option<Vec<u8>>Request body as bytes (if available)
content_type: Option<ContentType>Content type of the request body
remote_addr: Option<String>Remote address of the client
Implementations§
Source§impl HttpRequest
impl HttpRequest
Sourcepub async fn from_axum_request(axum_request: Request) -> Self
pub async fn from_axum_request(axum_request: Request) -> Self
Create an HttpRequest from an Axum Request.
This extracts all relevant metadata from the Axum request and parses query parameters.
§Example
use streamweave::http_server::HttpRequest;
use axum::extract::Request;
async fn process_request(axum_request: Request) {
let request = HttpRequest::from_axum_request(axum_request).await;
println!("Method: {:?}, Path: {}", request.method, request.path);
}Sourcepub fn get_query_param(&self, key: &str) -> Option<&String>
pub fn get_query_param(&self, key: &str) -> Option<&String>
Get a query parameter value by key.
Sourcepub fn get_path_param(&self, key: &str) -> Option<&String>
pub fn get_path_param(&self, key: &str) -> Option<&String>
Get a path parameter value by key.
Path parameters are extracted from route patterns (e.g., /users/:id).
§Example
use streamweave::http_server::HttpRequest;
let request = /* ... */;
if let Some(user_id) = request.get_path_param("id") {
println!("User ID: {}", user_id);
}Sourcepub fn get_header(&self, name: &str) -> Option<&HeaderValue>
pub fn get_header(&self, name: &str) -> Option<&HeaderValue>
Get a header value by name.
§Example
use streamweave::http_server::HttpRequest;
let request = /* ... */;
if let Some(auth) = request.get_header("authorization") {
println!("Auth: {:?}", auth);
}Sourcepub fn is_content_type(&self, content_type: ContentType) -> bool
pub fn is_content_type(&self, content_type: ContentType) -> bool
Check if the request has a specific content type.
§Example
use streamweave::http_server::{HttpRequest, ContentType};
let request = /* ... */;
if request.is_content_type(ContentType::Json) {
// Handle JSON request
}Sourcepub fn is_body_chunk(&self) -> bool
pub fn is_body_chunk(&self) -> bool
Check if this HttpRequest is a body chunk (from streaming mode).
When streaming is enabled, the producer yields:
- First: Request metadata with body = None
- Then: Body chunks with body = Some(chunk) and progress headers
§Example
use streamweave::http_server::HttpRequest;
let request = /* ... */;
if request.is_body_chunk() {
let offset = request.get_chunk_offset().unwrap_or(0);
let size = request.get_chunk_size().unwrap_or(0);
println!("Processing chunk at offset {} with size {}", offset, size);
}Sourcepub fn get_chunk_offset(&self) -> Option<u64>
pub fn get_chunk_offset(&self) -> Option<u64>
Get the byte offset of this body chunk (for progress tracking).
Returns None if this is not a body chunk or if the offset header is missing.
Sourcepub fn get_chunk_size(&self) -> Option<usize>
pub fn get_chunk_size(&self) -> Option<usize>
Get the size of this body chunk in bytes.
Returns None if this is not a body chunk or if the size header is missing.
Trait Implementations§
Source§impl Clone for HttpRequest
impl Clone for HttpRequest
Source§fn clone(&self) -> HttpRequest
fn clone(&self) -> HttpRequest
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more