Skip to main content

Context

Struct Context 

Source
pub struct Context<L: ListenerHandler + L7ListenerHandler> {
Show 18 fields pub streams: Vec<Stream>, pub pending_links: VecDeque<usize>, pub backend_streams: HashMap<Token, Vec<usize>>, pub pool: Weak<RefCell<Pool>>, pub listener: Rc<RefCell<L>>, pub session_ulid: Ulid, pub session_address: Option<SocketAddr>, pub public_address: SocketAddr, pub debug: DebugHistory, pub h2_stream_shrink_ratio: usize, pub tls_server_name: Option<String>, pub tls_cert_names: Option<Arc<Vec<String>>>, pub strict_sni_binding: bool, pub elide_x_real_ip: bool, pub send_x_real_ip: bool, pub tls_version: Option<&'static str>, pub tls_cipher: Option<&'static str>, pub tls_alpn: Option<&'static str>,
}

Fields§

§streams: Vec<Stream>§pending_links: VecDeque<usize>

Streams whose state is StreamState::Link and need backend connection. Replaces the O(n) scan of streams in the ready loop.

§backend_streams: HashMap<Token, Vec<usize>>

Reverse index: backend token -> global stream IDs currently in StreamState::Linked(token). Eliminates O(n) scans of streams when handling backend connect/disconnect/timeout/close events.

§pool: Weak<RefCell<Pool>>§listener: Rc<RefCell<L>>§session_ulid: Ulid

Connection/session ULID — mirrors Mux.session_ulid. Stored here so per-stream HttpContext construction in Self::create_stream can stamp the session slot of the log-context bracket without reaching back into the parent Mux.

§session_address: Option<SocketAddr>§public_address: SocketAddr§debug: DebugHistory§h2_stream_shrink_ratio: usize

Shrink threshold ratio for recycled stream slots. Vec is shrunk when total_slots > active_streams * ratio.

§tls_server_name: Option<String>

TLS SNI value negotiated at handshake, propagated to every per-stream HttpContext so the routing layer can enforce the SNI ↔ :authority binding on every H2 stream (and the single H1 request). None for plaintext listeners or when the client omitted the SNI extension. Stored pre-lowercased and without a port for cheap exact-match comparison.

§tls_cert_names: Option<Arc<Vec<String>>>

Snapshot of the SAN set of the certificate Sōzu actually served at the TLS handshake. Captured once in https.rs::upgrade_handshake from the resolver and frozen for the connection lifetime so H2 stream coalescing (RFC 7540 §9.1.1 / RFC 9113 §9.1.1) accepts any :authority covered by the certificate, with RFC 6125 §6.4.3 wildcard handling. None for plaintext listeners or when SNI was absent. Some(empty) when the default cert was served — every :authority is rejected. Arc so the snapshot is shared across every per-stream HttpContext without re-allocation.

§strict_sni_binding: bool

Whether the routing layer must reject any request whose authority host does not exact-match tls_server_name (CWE-346 / CWE-444). Mirrors HttpsListenerConfig::strict_sni_binding; captured once at Context::new so routing decisions on each stream avoid a per-stream listener.borrow().

§elide_x_real_ip: bool

Whether the request-side block walk must strip any client-supplied X-Real-IP header before forwarding (anti-spoofing). Mirrors HttpListenerConfig::elide_x_real_ip / HttpsListenerConfig::elide_x_real_ip; captured once at Context::new so per-stream HttpContexts do not need to call listener.borrow() again. Independent of send_x_real_ip.

§send_x_real_ip: bool

Whether on_request_headers injects a proxy-generated X-Real-IP header carrying the connection peer IP (post-PROXY-v2 unwrap). Mirrors HttpListenerConfig::send_x_real_ip / HttpsListenerConfig::send_x_real_ip; captured once at Context::new. Independent of elide_x_real_ip.

§tls_version: Option<&'static str>

Negotiated TLS protocol version short-form (e.g. "TLSv1.3"). Captured once at handshake completion in https.rs and propagated to every per-stream HttpContext so the access log can record it without reaching back into the rustls session per request. None for plaintext listeners.

§tls_cipher: Option<&'static str>

Negotiated TLS cipher suite short-form (e.g. "TLS_AES_128_GCM_SHA256"). Captured once at handshake completion and propagated to every per-stream HttpContext. None for plaintext listeners.

§tls_alpn: Option<&'static str>

Negotiated ALPN protocol short-form (e.g. "h2", "http/1.1"). Captured once at handshake completion and propagated to every per-stream HttpContext. None for plaintext listeners or when no ALPN was negotiated.

Implementations§

Source§

impl<L: ListenerHandler + L7ListenerHandler> Context<L>

Source

pub fn new( session_ulid: Ulid, pool: Weak<RefCell<Pool>>, listener: Rc<RefCell<L>>, session_address: Option<SocketAddr>, public_address: SocketAddr, ) -> Self

Source

pub fn active_len(&self) -> usize

Source

pub fn http_context(&self, stream_id: usize) -> &HttpContext

Shared accessor for the HttpContext owned by a stream.

Prefer this over &self.streams[stream_id].context at call sites that only need read access — it keeps the Stream/HttpContext relationship encapsulated and reads the same regardless of whether the caller is inside Router::connect, the H2 mux, or a free helper. Panics on an out-of-bounds stream_id, which is the same behaviour as the raw streams[sid] indexing it replaces.

Source

pub fn http_context_mut(&mut self, stream_id: usize) -> &mut HttpContext

Mutable sibling of Self::http_context. Use when routing decisions need to stamp cluster_id / backend_id on the stream’s HttpContext (e.g. Router::connect at the fill-cluster / fill-backend points).

Register a stream as linked to a backend token in the reverse index.

Remove a stream from the backend reverse index if it is currently Linked. Returns the backend token if one was removed.

Source

pub fn create_stream(&mut self, request_id: Ulid, window: u32) -> Option<usize>

Source

pub fn shrink_trailing_recycle(&mut self)

Remove consecutive Recycle entries from the end of the streams Vec.

This prevents unbounded growth when H2 streams are created and recycled over time, reclaiming memory from slots that are no longer needed.

Auto Trait Implementations§

§

impl<L> !RefUnwindSafe for Context<L>

§

impl<L> !Send for Context<L>

§

impl<L> !Sync for Context<L>

§

impl<L> !UnwindSafe for Context<L>

§

impl<L> Freeze for Context<L>

§

impl<L> Unpin for Context<L>

§

impl<L> UnsafeUnpin for Context<L>

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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