-
- All Implemented Interfaces:
ChannelHandler
public class SniHandler extends AbstractSniHandler<SslContext>
Enables SNI (Server Name Indication) extension for server side SSL. For clients support SNI, the server could have multiple host name bound on a single IP. The client will send host name in the handshake data so server could decide which certificate to choose for the host name.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.netty5.handler.codec.ByteToMessageDecoder
ByteToMessageDecoder.Cumulator
-
-
Field Summary
Fields Modifier and Type Field Description protected AsyncMapping<String,SslContext>
mapping
-
Fields inherited from class io.netty5.handler.codec.ByteToMessageDecoder
COMPOSITE_CUMULATOR, MERGE_CUMULATOR
-
-
Constructor Summary
Constructors Constructor Description SniHandler(AsyncMapping<? super String,? extends SslContext> mapping)
Creates a SNI detection handler with configuredSslContext
maintained byAsyncMapping
SniHandler(DomainNameMapping<? extends SslContext> mapping)
Creates a SNI detection handler with configuredSslContext
maintained byDomainNameMapping
SniHandler(Mapping<? super String,? extends SslContext> mapping)
Creates a SNI detection handler with configuredSslContext
maintained byMapping
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
hostname()
protected Future<SslContext>
lookup(ChannelHandlerContext ctx, String hostname)
The default implementation will simply callAsyncMapping.map(Object, Promise)
but users can override this method to implement custom behavior.protected SslHandler
newSslHandler(SslContext context, BufferAllocator allocator)
protected void
onLookupComplete(ChannelHandlerContext ctx, String hostname, Future<? extends SslContext> future)
Called upon completion of theAbstractSniHandler.lookup(ChannelHandlerContext, String)
Future
.protected void
replaceHandler(ChannelHandlerContext ctx, String hostname, SslContext sslContext)
The default implementation of this method will simply replacethis
SniHandler
instance with aSslHandler
.SslContext
sslContext()
-
Methods inherited from class io.netty5.handler.ssl.AbstractSniHandler
lookup, onLookupComplete
-
Methods inherited from class io.netty5.handler.ssl.SslClientHelloHandler
decode, handlerRemoved0, read
-
Methods inherited from class io.netty5.handler.codec.ByteToMessageDecoder
actualReadableBytes, channelInactive, channelRead, channelReadComplete, channelShutdown, decodeLast, discardSomeReadBytes, handlerAdded, handlerAdded0, handlerRemoved, internalBuffer, isSharable, isSingleDecode, setSingleDecode
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelActive, channelExceptionCaught, channelInboundEvent, channelRegistered, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, pendingOutboundBytes, register, sendOutboundEvent, shutdown, write
-
-
-
-
Field Detail
-
mapping
protected final AsyncMapping<String,SslContext> mapping
-
-
Constructor Detail
-
SniHandler
public SniHandler(Mapping<? super String,? extends SslContext> mapping)
Creates a SNI detection handler with configuredSslContext
maintained byMapping
- Parameters:
mapping
- the mapping of domain name toSslContext
-
SniHandler
public SniHandler(DomainNameMapping<? extends SslContext> mapping)
Creates a SNI detection handler with configuredSslContext
maintained byDomainNameMapping
- Parameters:
mapping
- the mapping of domain name toSslContext
-
SniHandler
public SniHandler(AsyncMapping<? super String,? extends SslContext> mapping)
Creates a SNI detection handler with configuredSslContext
maintained byAsyncMapping
- Parameters:
mapping
- the mapping of domain name toSslContext
-
-
Method Detail
-
hostname
public String hostname()
- Returns:
- the selected hostname
-
sslContext
public SslContext sslContext()
- Returns:
- the selected
SslContext
-
lookup
protected Future<SslContext> lookup(ChannelHandlerContext ctx, String hostname) throws Exception
The default implementation will simply callAsyncMapping.map(Object, Promise)
but users can override this method to implement custom behavior.- Specified by:
lookup
in classAbstractSniHandler<SslContext>
- Throws:
Exception
- See Also:
AsyncMapping.map(Object, Promise)
-
onLookupComplete
protected final void onLookupComplete(ChannelHandlerContext ctx, String hostname, Future<? extends SslContext> future) throws Exception
Description copied from class:AbstractSniHandler
Called upon completion of theAbstractSniHandler.lookup(ChannelHandlerContext, String)
Future
.- Specified by:
onLookupComplete
in classAbstractSniHandler<SslContext>
- Throws:
Exception
- See Also:
AbstractSniHandler.lookup(ChannelHandlerContext, String)
-
replaceHandler
protected void replaceHandler(ChannelHandlerContext ctx, String hostname, SslContext sslContext) throws Exception
The default implementation of this method will simply replacethis
SniHandler
instance with aSslHandler
. Users may override this method to implement custom behavior. Please be aware that this method may get called after a client has already disconnected and custom implementations must take it into consideration when overriding this method. It's also possible for the hostname argument to benull
.- Throws:
Exception
-
newSslHandler
protected SslHandler newSslHandler(SslContext context, BufferAllocator allocator)
Returns a newSslHandler
using the givenSslContext
andBufferAllocator
. Users may override this method to implement custom behavior.
-
-