Skip to main content

CacheableHttpRequest

Struct CacheableHttpRequest 

Source
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 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: Body,

Source

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.

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

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,

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

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

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, ) -> (<CacheableHttpRequest<ReqBody> as CacheableSubject>::Parts, BufferedBody<<CacheableHttpRequest<ReqBody> as CacheableSubject>::Body>)

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

fn from_parts( parts: <CacheableHttpRequest<ReqBody> as CacheableSubject>::Parts, body: BufferedBody<<CacheableHttpRequest<ReqBody> as CacheableSubject>::Body>, ) -> CacheableHttpRequest<ReqBody>

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

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

Source§

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

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

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

Source§

fn headers(&self) -> &HeaderMap

Returns a reference to the HTTP headers.
Source§

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

Source§

fn http_version(&self) -> Version

Returns the HTTP protocol version.
Source§

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.

Source§

type Response = Result<CacheableHttpResponse<Body>, Error>

The response type returned by the upstream service
Source§

type Future = Pin<Box<dyn Future<Output = <ReqwestUpstream<'a> as Upstream<CacheableHttpRequest<Body>>>::Response> + Send + 'a>>

The future that resolves to the response
Source§

fn call(&mut self, req: CacheableHttpRequest<Body>) -> Self::Future

Call the upstream service with the given request

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,