expression

Configure ALPN protocol offers

ALPN allows a TLS client and server to negotiate an application protocol from compatible offers. The configuration list is not the negotiated result; the application must use the actual negotiated protocol after the handshake. No connection is attempted here. External crate example; candidate dependency is not approved for deployment. Expected stdout (not executed): 2 Common mistake: Treating the first offered protocol as the negotiated protocol before a handshake.

Formal Syntax & Structure

rust syntaxrust
config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]

Working Example

Example Snippetrust
fn main() {    use rustls::{ClientConfig, RootCertStore};    let mut config = ClientConfig::builder().with_root_certificates(RootCertStore::empty()).with_no_client_auth();    config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()];    println!("{}", config.alpn_protocols.len());}
Rust Reference