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: h2chandler, ever: the HTTP/1.1 state machine forwardsUpgradeheaders to the backend but never responds101 Switching Protocolswith an HTTP/2 connection preface. RFC 9113 deprecates the mechanism. - Prior knowledge is opt-in per listener (
h2c_prior_knowledge, defaultfalse, sozu-proxy/sozu#1911). When set, the session starts inH2cPrefaceSniff(lib/src/protocol/h2c.rs), which peeks at the first bytes without consuming them: the 24-bytePRI * HTTP/2.0\r\n\r\nSM\r\n\r\npreface makes the connection an HTTP/2 frontend, exactly as ALPNh2does onHttpsListener, 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
impl HttpListener
Sourcepub fn key(&self) -> ListenerKey
pub fn key(&self) -> ListenerKey
This listener’s identity: its address, plus the network interface its socket is bound to when it has one.
Sourcepub fn is(&self, key: &ListenerKey) -> bool
pub fn is(&self, key: &ListenerKey) -> bool
Whether this listener is the one key names.
pub fn new( config: HttpListenerConfig, token: Token, ) -> Result<HttpListener, ListenerError>
Sourcepub fn validate_config(config: &HttpListenerConfig) -> Result<(), ListenerError>
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.
pub fn activate( &mut self, registry: &Registry, tcp_listener: Option<MioTcpListener>, ) -> Result<Token, ListenerError>
Sourcepub fn update_config(
&mut self,
patch: &UpdateHttpListenerConfig,
) -> Result<(), ListenerError>
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.
pub fn add_http_front( &mut self, http_front: HttpFrontend, ) -> Result<(), ListenerError>
pub fn remove_http_front( &mut self, http_front: HttpFrontend, ) -> Result<(), ListenerError>
Trait Implementations§
Source§impl L7ListenerHandler for HttpListener
impl L7ListenerHandler for HttpListener
fn get_sticky_name(&self) -> &str
Source§fn get_sozu_id_header(&self) -> &str
fn get_sozu_id_header(&self) -> &str
"Sozu-Id". Operators can rebrand via the
sozu_id_header listener config knob.fn get_connect_timeout(&self) -> u32
Source§fn frontend_from_request(
&self,
host: &str,
uri: &str,
method: &Method,
headers: &dyn RequestHeaders,
) -> Result<RouteResult, FrontendFromRequestError>
fn frontend_from_request( &self, host: &str, uri: &str, method: &Method, headers: &dyn RequestHeaders, ) -> Result<RouteResult, FrontendFromRequestError>
Source§fn get_answers(&self) -> &Rc<RefCell<HttpAnswers>>
fn get_answers(&self) -> &Rc<RefCell<HttpAnswers>>
Source§fn get_h2_flood_config(&self) -> H2FloodConfig
fn get_h2_flood_config(&self) -> H2FloodConfig
Source§fn get_h2_connection_config(&self) -> H2ConnectionConfig
fn get_h2_connection_config(&self) -> H2ConnectionConfig
Source§fn get_h2_stream_idle_timeout(&self) -> Duration
fn get_h2_stream_idle_timeout(&self) -> Duration
Source§fn get_h2_graceful_shutdown_deadline(&self) -> Option<Duration>
fn get_h2_graceful_shutdown_deadline(&self) -> Option<Duration>
GOAWAY(NO_ERROR). Once the deadline elapses the mux
transitions to a forced close (final GOAWAY + session teardown). Read moreSource§fn get_elide_x_real_ip(&self) -> bool
fn get_elide_x_real_ip(&self) -> bool
X-Real-IP header from
forwarded requests (anti-spoofing). Read moreSource§fn get_send_x_real_ip(&self) -> bool
fn get_send_x_real_ip(&self) -> bool
X-Real-IP header carrying the
connection peer IP (post-PROXY-v2 unwrap, i.e. the original client
IP) to every forwarded request. Read moreSource§fn get_forwarded_headers(&self) -> ForwardedHeaders
fn get_forwarded_headers(&self) -> ForwardedHeaders
X-Forwarded-*, RFC 7239 Forwarded, both, or none. Read moreSource§fn get_strict_sni_binding(&self) -> bool
fn get_strict_sni_binding(&self) -> bool
:authority / Host exact-match
the TLS SNI negotiated at handshake (CWE-346 / CWE-444). Read more