hyper-rustls icon indicating copy to clipboard operation
hyper-rustls copied to clipboard

More elaborate custom server name

Open DarkCWK opened this issue 3 years ago • 1 comments

let https = HttpsConnectorBuilder::new()
            .with_native_roots()
            .https_only()
            .with_server_name("override_server_name")
            .enable_http1()
            .build();

// change it to

let https = HttpsConnectorBuilder::new()
            .with_native_roots()
            .https_only()
            .with_server_name(|request| {
                // Compute server name
                return "override_server_name";
            })
            .enable_http1()
            .build();

This allows different server names to be injected for different ip requests

DarkCWK avatar Mar 13 '23 08:03 DarkCWK

Makes sense, I think. Would you like to submit a PR? I think we can change it to do something like this:

trait ServerNameResolver {
    fn resolve(&self, uri: Uri) -> Result<ServerName, Box<dyn std::error::Error + Send + Sync>>;
}

It should probably come with impls for String (current approach) and impl Fn(uri: Uri) -> Result<ServerName, Box<dyn std::error::Error + Send + Sync>.

djc avatar Mar 13 '23 09:03 djc