expression
HTTP/2 and HTTP/3: interpret negotiated ALPN labels
ALPN identifies an agreed application protocol during a TLS handshake. Interpret a negotiated label supplied by the transport, not a user-provided header. h2 represents HTTP/2 over TLS; h3 represents HTTP/3 over QUIC. This code only labels synthetic values. Expected stdout (not executed): h2: TCP with TLS h3: QUIC http/1.1: TCP with TLS unknown: unsupported by this model Common mistake: Setting a string and assuming a real connection was negotiated.
Formal Syntax & Structure
rust syntaxrust
match selected_protocol { "h2" => ..., "h3" => ..., _ => ... }Working Example
Example Snippetrust
fn main() { for protocol in ["h2", "h3", "http/1.1", "unknown"] { let transport = match protocol { "h2" | "http/1.1" => "TCP with TLS", "h3" => "QUIC", _ => "unsupported by this model", }; println!("{protocol}: {transport}"); }}