pub struct CacheableHttpRequest<ReqBody>where
ReqBody: Body,{ /* 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: Body,
impl<ReqBody> CacheableHttpRequest<ReqBody>where
ReqBody: Body,
Sourcepub fn from_request(
request: Request<BufferedBody<ReqBody>>,
) -> CacheableHttpRequest<ReqBody>
pub fn from_request( request: Request<BufferedBody<ReqBody>>, ) -> CacheableHttpRequest<ReqBody>
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§async fn cache_policy<P, E>(
self,
predicates: P,
extractors: E,
) -> CachePolicy<CacheablePolicyData<CacheableHttpRequest<ReqBody>>, CacheableHttpRequest<ReqBody>>where
P: Predicate<Subject = CacheableHttpRequest<ReqBody>> + Send + Sync,
E: Extractor<Subject = CacheableHttpRequest<ReqBody>> + Send + Sync,
async fn cache_policy<P, E>(
self,
predicates: P,
extractors: E,
) -> CachePolicy<CacheablePolicyData<CacheableHttpRequest<ReqBody>>, CacheableHttpRequest<ReqBody>>where
P: Predicate<Subject = CacheableHttpRequest<ReqBody>> + Send + Sync,
E: Extractor<Subject = CacheableHttpRequest<ReqBody>> + Send + Sync,
Source§impl<ReqBody> CacheableSubject for CacheableHttpRequest<ReqBody>where
ReqBody: Body,
impl<ReqBody> CacheableSubject for CacheableHttpRequest<ReqBody>where
ReqBody: Body,
Source§type Parts = Parts
type Parts = Parts
http::request::Parts or http::response::Parts).Source§fn into_parts(
self,
) -> (<CacheableHttpRequest<ReqBody> as CacheableSubject>::Parts, BufferedBody<<CacheableHttpRequest<ReqBody> as CacheableSubject>::Body>)
fn into_parts( self, ) -> (<CacheableHttpRequest<ReqBody> as CacheableSubject>::Parts, BufferedBody<<CacheableHttpRequest<ReqBody> as CacheableSubject>::Body>)
Source§fn from_parts(
parts: <CacheableHttpRequest<ReqBody> as CacheableSubject>::Parts,
body: BufferedBody<<CacheableHttpRequest<ReqBody> as CacheableSubject>::Body>,
) -> CacheableHttpRequest<ReqBody>
fn from_parts( parts: <CacheableHttpRequest<ReqBody> as CacheableSubject>::Parts, body: BufferedBody<<CacheableHttpRequest<ReqBody> as CacheableSubject>::Body>, ) -> CacheableHttpRequest<ReqBody>
Source§impl<ReqBody> Debug for CacheableHttpRequest<ReqBody>
impl<ReqBody> Debug for CacheableHttpRequest<ReqBody>
Source§impl<ReqBody> HasHeaders for CacheableHttpRequest<ReqBody>where
ReqBody: Body,
impl<ReqBody> HasHeaders for CacheableHttpRequest<ReqBody>where
ReqBody: Body,
Source§impl<ReqBody> HasVersion for CacheableHttpRequest<ReqBody>where
ReqBody: Body,
impl<ReqBody> HasVersion for CacheableHttpRequest<ReqBody>where
ReqBody: Body,
Source§fn http_version(&self) -> Version
fn http_version(&self) -> Version
Source§impl<'a> Upstream<CacheableHttpRequest<Body>> for ReqwestUpstream<'a>
Implementation of Upstream for reqwest-middleware integration.
impl<'a> Upstream<CacheableHttpRequest<Body>> for ReqwestUpstream<'a>
Implementation of Upstream for reqwest-middleware integration.
This allows the hitbox cache FSM to treat the remaining middleware chain as an upstream service that can be called on cache misses.