@@ -45,13 +45,19 @@ pub(crate) struct ConnectionMeta {
4545 pub peer_endpoint : Option < Endpoint > ,
4646 #[ cfg_attr( not( feature = "mtls" ) , allow( dead_code) ) ]
4747 pub peer_certs : Option < Arc < Certificates < ' static > > > ,
48+ #[ cfg_attr( feature = "tls" , allow( dead_code) ) ]
49+ pub server_name : Option < String > ,
4850}
4951
5052impl ConnectionMeta {
51- pub fn new ( endpoint : io:: Result < Endpoint > , certs : Option < Certificates < ' _ > > ) -> Self {
53+ pub fn new (
54+ endpoint : io:: Result < Endpoint > ,
55+ certs : Option < Certificates < ' _ > > ,
56+ server_name : Option < & str > ) -> Self {
5257 ConnectionMeta {
5358 peer_endpoint : endpoint. ok ( ) ,
5459 peer_certs : certs. map ( |c| c. into_owned ( ) ) . map ( Arc :: new) ,
60+ server_name : server_name. map ( |s| s. to_string ( ) ) ,
5561 }
5662 }
5763}
@@ -295,6 +301,16 @@ impl<'r> Request<'r> {
295301 self . state . host . as_ref ( )
296302 }
297303
304+ /// Returns the resolved SNI server name requested in the TLS handshake, if
305+ /// any.
306+ ///
307+ /// Ideally, this will match the `Host` header in the request.
308+ #[ cfg( feature = "tls" ) ]
309+ #[ inline( always) ]
310+ pub fn sni ( & mut self ) -> Option < & str > {
311+ self . connection . server_name . as_deref ( )
312+ }
313+
298314 /// Sets the host of `self` to `host`.
299315 ///
300316 /// # Example
0 commit comments