Skip to main content

HttpListener

Struct HttpListener 

Source
pub struct HttpListener { /* private fields */ }
Expand description

Cleartext HTTP listener: HTTP/1.x, plus HTTP/2 by prior knowledge when h2c_prior_knowledge is set.

§HTTP/2 over cleartext (h2c)

RFC 7540 §3.2 specified an Upgrade: h2c mechanism to negotiate HTTP/2 over a cleartext TCP connection, with a companion prior-knowledge variant in §3.4 (RFC 9113 §3.3 keeps only the latter):

  • No Upgrade: h2c handler, ever: the HTTP/1.1 state machine forwards Upgrade headers to the backend but never responds 101 Switching Protocols with an HTTP/2 connection preface. RFC 9113 deprecates the mechanism.
  • Prior knowledge is opt-in per listener (h2c_prior_knowledge, default false, sozu-proxy/sozu#1911). When set, the session starts in H2cPrefaceSniff (lib/src/protocol/h2c.rs), which peeks at the first bytes without consuming them: the 24-byte PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n preface makes the connection an HTTP/2 frontend, exactly as ALPN h2 does on HttpsListener, and any diverging byte makes it HTTP/1.x. When unset — the default — no sniff runs at all, and a client that opens with the preface is interpreted as a malformed HTTP/1 request and rejected with 400.

Keeping the knob off by default keeps cleartext HTTP/2, and the cleartext-preface smuggling primitives it can carry, away from listeners that never asked for it; clients that want HTTP/2 there use the TLS ALPN path (HttpsListener, selector h2).

Implementations§

Source§

impl HttpListener

Source

pub fn key(&self) -> ListenerKey

This listener’s identity: its address, plus the network interface its socket is bound to when it has one.

Source

pub fn is(&self, key: &ListenerKey) -> bool

Whether this listener is the one key names.

Source

pub fn new( config: HttpListenerConfig, token: Token, ) -> Result<HttpListener, ListenerError>

Source

pub fn validate_config(config: &HttpListenerConfig) -> Result<(), ListenerError>

Validate that a worker can build this HTTP listener configuration (its answer templates) WITHOUT constructing the full listener or binding a socket. The main process calls this before committing an AddHttpListener to its ConfigState and fanning it out, so an invalid listener never reserves its address and blocks a corrected reload (sozu#1301).

Buildability only. The H2 knob floors are deliberately NOT checked here (sozu#1418): a worker can build a listener whose threshold is out of range — H2FloodConfig::from_optional clamps it — so refusing it is a policy the command socket applies to what an operator is authoring, not a statement about what a worker can construct. That gate lives beside its audience, in bin/src/command/requests.rs::validate_h2_knob_floors.

Source

pub fn activate( &mut self, registry: &Registry, tcp_listener: Option<MioTcpListener>, ) -> Result<Token, ListenerError>

Source

pub fn update_config( &mut self, patch: &UpdateHttpListenerConfig, ) -> Result<(), ListenerError>

Apply a partial-update patch to this listener’s live configuration.

Fields absent in the patch (i.e. None) are preserved unchanged. If http_answers is present only the listener-default templates are replaced; per-cluster overrides in cluster_custom_answers are kept.

All-or-nothing (sozu-proxy/sozu#1703): the patch is validated, then applied to a copy of the configuration, and every fallible artifact (the rebuilt answer registry) is built from that copy. Only once all of it succeeded are the copy and the artifacts committed, so a refused patch leaves the listener exactly as it was. The copy is one HttpListenerConfig clone per patch, on the command path only.

Source

pub fn add_http_front( &mut self, http_front: HttpFrontend, ) -> Result<(), ListenerError>

Source

pub fn remove_http_front( &mut self, http_front: HttpFrontend, ) -> Result<(), ListenerError>

Trait Implementations§

Source§

impl L7ListenerHandler for HttpListener

Source§

fn get_sticky_name(&self) -> &str

Source§

fn get_sozu_id_header(&self) -> &str

Name of the correlation header Sozu injects into every request and response body. Default: "Sozu-Id". Operators can rebrand via the sozu_id_header listener config knob.
Source§

fn get_connect_timeout(&self) -> u32

Source§

fn frontend_from_request( &self, host: &str, uri: &str, method: &Method, headers: &dyn RequestHeaders, ) -> Result<RouteResult, FrontendFromRequestError>

retrieve a frontend by parsing a request’s hostname, uri and method, with its headers for the frontends that carry header predicates (sozu-proxy/sozu#1253)
Source§

fn get_answers(&self) -> &Rc<RefCell<HttpAnswers>>

retrieve the listener’s configured HTTP answers (templates)
Source§

fn get_h2_flood_config(&self) -> H2FloodConfig

H2 flood detection thresholds from the listener config. Returns the default config when the listener does not provide custom values.
Source§

fn get_h2_connection_config(&self) -> H2ConnectionConfig

H2 connection tuning from the listener config. Returns the default config when the listener does not provide custom values.
Source§

fn get_h2_stream_idle_timeout(&self) -> Duration

Per-stream idle timeout for H2 connections. An open stream that makes no forward progress for this duration is cancelled (RST_STREAM / CANCEL). Mitigates slow-multiplex Slowloris where a client keeps connection-level activity high (resetting the connection idle timer on every frame) while pinning streams for the full nominal connection timeout. Read more
Source§

fn get_h2_graceful_shutdown_deadline(&self) -> Option<Duration>

Wall-clock budget granted to in-flight H2 streams after soft-stop sent the initial GOAWAY(NO_ERROR). Once the deadline elapses the mux transitions to a forced close (final GOAWAY + session teardown). Read more
Source§

fn get_elide_x_real_ip(&self) -> bool

Whether to strip any client-supplied X-Real-IP header from forwarded requests (anti-spoofing). Read more
Source§

fn get_send_x_real_ip(&self) -> bool

Whether to append a proxy-generated X-Real-IP header carrying the connection peer IP (post-PROXY-v2 unwrap, i.e. the original client IP) to every forwarded request. Read more
Source§

fn get_forwarded_headers(&self) -> ForwardedHeaders

Which forwarding header family to add to every forwarded request: X-Forwarded-*, RFC 7239 Forwarded, both, or none. Read more
Source§

fn get_strict_sni_binding(&self) -> bool

Whether requests must have their :authority / Host exact-match the TLS SNI negotiated at handshake (CWE-346 / CWE-444). Read more
Source§

impl ListenerHandler for HttpListener

Auto Trait Implementations§

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, 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.