Skip to main content

CacheableHttpRequest

Struct CacheableHttpRequest 

Source
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 implement hyper::body::Body with Send bounds. Common concrete types:
    • Empty<Bytes> - No body (GET requests)
    • Full<Bytes> - Complete body in memory
    • BoxBody<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,

Source

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.

Source

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.

Source

pub fn parts(&self) -> &Parts

Returns a reference to the request metadata.

The Parts contain the method, URI, version, headers, and extensions.

Source

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>
where ReqBody: HttpBody + Send + 'static, ReqBody::Error: Send,

Source§

async fn cache_policy<P, E>( self, predicates: P, extractors: E, ) -> RequestCachePolicy<Self>
where P: Predicate<Subject = Self> + Send + Sync, E: Extractor<Subject = Self> + Send + Sync,

Determine if this request should be cached and extract its key. Read more
Source§

impl<ReqBody> CacheableSubject for CacheableHttpRequest<ReqBody>
where ReqBody: HttpBody,

Source§

type Body = ReqBody

The HTTP body type.
Source§

type Parts = Parts

The metadata type (e.g., http::request::Parts or http::response::Parts).
Source§

fn into_parts(self) -> (Self::Parts, BufferedBody<Self::Body>)

Decomposes this subject into metadata and body. Read more
Source§

fn from_parts(parts: Self::Parts, body: BufferedBody<Self::Body>) -> Self

Reconstructs a subject from metadata and body. Read more
Source§

impl<ReqBody> Debug for CacheableHttpRequest<ReqBody>
where ReqBody: HttpBody + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<ReqBody> HasHeaders for CacheableHttpRequest<ReqBody>
where ReqBody: HttpBody,

Source§

fn headers(&self) -> &HeaderMap

Returns a reference to the HTTP headers.
Source§

impl<ReqBody> HasVersion for CacheableHttpRequest<ReqBody>
where ReqBody: HttpBody,

Source§

fn http_version(&self) -> Version

Returns the HTTP protocol version.

Auto Trait Implementations§

§

impl<ReqBody> !Freeze for CacheableHttpRequest<ReqBody>

§

impl<ReqBody> !RefUnwindSafe for CacheableHttpRequest<ReqBody>

§

impl<ReqBody> Send for CacheableHttpRequest<ReqBody>
where ReqBody: Send, <ReqBody as Body>::Error: Send,

§

impl<ReqBody> Sync for CacheableHttpRequest<ReqBody>
where ReqBody: Sync, <ReqBody as Body>::Error: Sync,

§

impl<ReqBody> Unpin for CacheableHttpRequest<ReqBody>
where ReqBody: Unpin,

§

impl<ReqBody> !UnwindSafe for CacheableHttpRequest<ReqBody>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more