Skip to main content

RequestCtx

Struct RequestCtx 

Source
pub struct RequestCtx<'a> { /* private fields */ }
Expand description

The read-only view of an authenticated request given to the SPI to decide routing.

For M1 (single-doc ingest) the body is provided as a borrowed byte slice: one document fits comfortably in memory. Streaming body access for bulk arrives with the demux work in M3 (docs/04 §3); the field is intentionally accessed only through RequestCtx::body so that change stays internal.

§Examples

use osproxy_spi::{RequestCtx, HttpMethod, Protocol, HeaderView, Principal};
use osproxy_spi::core::{PrincipalId, RequestId, EndpointKind};

let principal = Principal::new(PrincipalId::from("svc"));
let rid = RequestId::from("req-1");
let headers = vec![("x-tenant".to_owned(), "acme".to_owned())];
let ctx = RequestCtx::new(
    &principal,
    &rid,
    HttpMethod::Put,
    EndpointKind::IngestDoc,
    Protocol::Http1,
    "orders",
    HeaderView::new(&headers),
    b"{}",
);
assert_eq!(ctx.logical_index(), "orders");
assert_eq!(ctx.headers().get("x-tenant"), Some("acme"));

Implementations§

Source§

impl<'a> RequestCtx<'a>

Source

pub fn new( principal: &'a Principal, request_id: &'a RequestId, method: HttpMethod, endpoint: EndpointKind, protocol: Protocol, logical_index: &'a str, headers: HeaderView<'a>, body: &'a [u8], ) -> Self

Constructs a request context from its already-authenticated parts.

Source

pub fn with_forward_headers( self, forward_headers: &'a [(String, String)], ) -> Self

Sets the client headers to forward verbatim to the upstream (builder style). Distinct from headers: that view is the auth-stripped set used for routing and observability, while this is the policy-sanitized set the proxy relays to the cluster (which may include the client’s Authorization and vendor trace headers). Empty by default, so the upstream sees only the proxy-managed headers unless the binding fills it.

Source

pub fn with_path(self, path: &'a str) -> Self

Sets the raw request path (e.g. /_cat/indices). Builder style. Used by the admin pass-through, which forwards the path verbatim to the configured admin cluster; the tenancy-aware paths derive their index/id at classify time and do not consult it.

Source

pub fn with_doc_id(self, doc_id: Option<&'a str>) -> Self

Sets the document id from the request path (e.g. _doc/{id}), present on by-id reads/writes. Builder style; RequestCtx is Copy (docs/04 §5).

Source

pub fn with_query(self, query: Option<&'a str>) -> Self

Sets the raw URL query string (without the ?). Builder style. Only an allow-list of cursor params (scroll/keep_alive) is ever forwarded upstream, query-affecting params are dropped so the body partition filter cannot be bypassed (NFR-S4).

Source

pub fn principal(&self) -> &Principal

The authenticated caller.

Source

pub fn principal_id(&self) -> &PrincipalId

The principal’s id (convenience).

Source

pub fn request_id(&self) -> &RequestId

The request correlation id (telemetry).

Source

pub fn method(&self) -> HttpMethod

The HTTP method.

Source

pub fn endpoint(&self) -> EndpointKind

The endpoint classification.

Source

pub fn protocol(&self) -> Protocol

The ingress protocol.

Source

pub fn logical_index(&self) -> &str

The logical index from the request path (pre-rewrite).

Source

pub fn doc_id(&self) -> Option<&'a str>

The client-supplied document id from the path, if the endpoint carries one (GetById/DeleteById/by-id ingest). This is the logical id; the tenancy layer maps it to the physical id (docs/04 §5).

Source

pub fn query(&self) -> Option<&'a str>

The raw URL query string (without the ?), if any. Consumers must forward only an allow-list of cursor params (scroll/keep_alive) upstream.

Source

pub fn path(&self) -> &'a str

The raw request path, if set (with_path). Empty unless the consumer attached it; the admin pass-through forwards it verbatim upstream.

Source

pub fn headers(&self) -> HeaderView<'a>

The request headers.

Source

pub fn forward_headers(&self) -> &'a [(String, String)]

The client headers to forward verbatim to the upstream (with_forward_headers), or an empty slice if none were attached.

Source

pub fn body(&self) -> &'a [u8]

The raw request body.

Trait Implementations§

Source§

impl<'a> Clone for RequestCtx<'a>

Source§

fn clone(&self) -> RequestCtx<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for RequestCtx<'a>

Source§

impl<'a> Debug for RequestCtx<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for RequestCtx<'a>

§

impl<'a> RefUnwindSafe for RequestCtx<'a>

§

impl<'a> Send for RequestCtx<'a>

§

impl<'a> Sync for RequestCtx<'a>

§

impl<'a> Unpin for RequestCtx<'a>

§

impl<'a> UnsafeUnpin for RequestCtx<'a>

§

impl<'a> UnwindSafe for RequestCtx<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.