pub struct CacheableHttpRequest<ReqBody>where
ReqBody: HttpBody,{ /* private fields */ }Expand description
Wraps an HTTP request for cache policy evaluation.
This type holds the request metadata (Parts) and a BufferedBody that
allows predicates and extractors to inspect the request without fully consuming
the body stream.
§Type Parameters
ReqBody- The HTTP request body type. Must implementhyper::body::BodywithSendbounds. Common concrete types:Empty<Bytes>- No body (GET requests)Full<Bytes>- Complete body in memoryBoxBody<Bytes, E>- Type-erased body for dynamic dispatch
§Examples
use bytes::Bytes;
use http::Request;
use http_body_util::Empty;
use hitbox_http::{BufferedBody, CacheableHttpRequest};
let request = Request::builder()
.method("GET")
.uri("/users/42")
.header("Authorization", "Bearer token")
.body(BufferedBody::Passthrough(Empty::<Bytes>::new()))
.unwrap();
let cacheable = CacheableHttpRequest::from_request(request);§Extracting Cache Keys
Use with extractors to generate cache key parts:
use hitbox::Extractor;
use hitbox_http::CacheableHttpRequest;
use hitbox_http::extractors::{Method, path::PathExtractor};
async fn example(cacheable: CacheableHttpRequest<Empty<Bytes>>) {
let extractor = Method::new().path("/users/{user_id}");
let key_parts = extractor.get(cacheable).await;
}Implementations§
Source§impl<ReqBody> CacheableHttpRequest<ReqBody>where
ReqBody: HttpBody,
impl<ReqBody> CacheableHttpRequest<ReqBody>where
ReqBody: HttpBody,
Sourcepub fn from_request(request: Request<BufferedBody<ReqBody>>) -> Self
pub fn from_request(request: Request<BufferedBody<ReqBody>>) -> Self
Creates a cacheable request from an HTTP request with a buffered body.
The request body must already be wrapped in a BufferedBody. Use
BufferedBody::Passthrough for requests that haven’t been inspected yet.
Sourcepub fn into_request(self) -> Request<BufferedBody<ReqBody>>
pub fn into_request(self) -> Request<BufferedBody<ReqBody>>
Converts back into a standard HTTP request.
Use this after cache policy evaluation to continue processing the request.
Sourcepub fn parts(&self) -> &Parts
pub fn parts(&self) -> &Parts
Returns a reference to the request metadata.
The Parts contain the method, URI, version, headers, and extensions.
Sourcepub fn into_parts(self) -> (Parts, BufferedBody<ReqBody>)
pub fn into_parts(self) -> (Parts, BufferedBody<ReqBody>)
Decomposes into metadata and body.
This is equivalent to CacheableSubject::into_parts.
Trait Implementations§
Source§impl<ReqBody> CacheableRequest for CacheableHttpRequest<ReqBody>
impl<ReqBody> CacheableRequest for CacheableHttpRequest<ReqBody>
Source§impl<ReqBody> CacheableSubject for CacheableHttpRequest<ReqBody>where
ReqBody: HttpBody,
impl<ReqBody> CacheableSubject for CacheableHttpRequest<ReqBody>where
ReqBody: HttpBody,
Source§type Parts = Parts
type Parts = Parts
http::request::Parts or http::response::Parts).