boost::corosio::tls_context::set_servername_callback

Set a callback for Server Name Indication (SNI).

Synopsis

template<typename Callback>
void
set_servername_callback(Callback callback);

Description

For server connections, this callback is invoked during the TLS handshake when a client sends an SNI extension. The callback receives the requested hostname and can accept or reject the connection.

Example

// Accept connections for specific domains only
ctx.set_servername_callback(
    []( std::string_view hostname ) -> bool
    {
        return hostname == "api.example.com" ||
               hostname == "www.example.com";
    });

For virtual hosting with different certificates per hostname, create separate contexts and select the appropriate one before creating the TLS stream.

Template Parameters

Name Description

Callback

A callable with signature bool( std::string_view hostname ).

Parameters

Name Description

callback

The SNI callback. Return true to accept the connection or false to reject it with an alert.

See Also

set_hostname

Created with MrDocs