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>
impl<'a> RequestCtx<'a>
Sourcepub 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
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.
Sourcepub fn with_forward_headers(
self,
forward_headers: &'a [(String, String)],
) -> Self
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.
Sourcepub fn with_path(self, path: &'a str) -> Self
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.
Sourcepub fn with_doc_id(self, doc_id: Option<&'a str>) -> Self
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).
Sourcepub fn with_query(self, query: Option<&'a str>) -> Self
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).
Sourcepub fn principal_id(&self) -> &PrincipalId
pub fn principal_id(&self) -> &PrincipalId
The principal’s id (convenience).
Sourcepub fn request_id(&self) -> &RequestId
pub fn request_id(&self) -> &RequestId
The request correlation id (telemetry).
Sourcepub fn method(&self) -> HttpMethod
pub fn method(&self) -> HttpMethod
The HTTP method.
Sourcepub fn endpoint(&self) -> EndpointKind
pub fn endpoint(&self) -> EndpointKind
The endpoint classification.
Sourcepub fn logical_index(&self) -> &str
pub fn logical_index(&self) -> &str
The logical index from the request path (pre-rewrite).
Sourcepub fn doc_id(&self) -> Option<&'a str>
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).
Sourcepub fn query(&self) -> Option<&'a str>
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.
Sourcepub fn path(&self) -> &'a str
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.
Sourcepub fn headers(&self) -> HeaderView<'a>
pub fn headers(&self) -> HeaderView<'a>
The request headers.
Sourcepub fn forward_headers(&self) -> &'a [(String, String)]
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.
Trait Implementations§
Source§impl<'a> Clone for RequestCtx<'a>
impl<'a> Clone for RequestCtx<'a>
Source§fn clone(&self) -> RequestCtx<'a>
fn clone(&self) -> RequestCtx<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more