- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.handler.codec.ByteToMessageDecoder
-
- io.netty5.handler.ssl.SslClientHelloHandler<T>
-
- io.netty5.handler.ssl.AbstractSniHandler<SslContext>
-
- io.netty5.handler.ssl.SniHandler
-
- All Implemented Interfaces:
io.netty5.channel.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.
-
-
Field Summary
Fields Modifier and Type Field Description protected io.netty5.util.AsyncMapping<String,SslContext>
mapping
-
Constructor Summary
Constructors Constructor Description SniHandler(io.netty5.util.AsyncMapping<? super String,? extends SslContext> mapping)
Creates a SNI detection handler with configuredSslContext
maintained byAsyncMapping
SniHandler(io.netty5.util.DomainNameMapping<? extends SslContext> mapping)
Creates a SNI detection handler with configuredSslContext
maintained byDomainNameMapping
SniHandler(io.netty5.util.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 io.netty5.util.concurrent.Future<SslContext>
lookup(io.netty5.channel.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, io.netty5.buffer.api.BufferAllocator allocator)
protected void
onLookupComplete(io.netty5.channel.ChannelHandlerContext ctx, String hostname, io.netty5.util.concurrent.Future<? extends SslContext> future)
Called upon completion of theAbstractSniHandler.lookup(ChannelHandlerContext, String)
Future
.protected void
replaceHandler(io.netty5.channel.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 io.netty5.util.AsyncMapping<String,SslContext> mapping
-
-
Constructor Detail
-
SniHandler
public SniHandler(io.netty5.util.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(io.netty5.util.DomainNameMapping<? extends SslContext> mapping)
Creates a SNI detection handler with configuredSslContext
maintained byDomainNameMapping
- Parameters:
mapping
- the mapping of domain name toSslContext
-
SniHandler
public SniHandler(io.netty5.util.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 io.netty5.util.concurrent.Future<SslContext> lookup(io.netty5.channel.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(io.netty5.channel.ChannelHandlerContext ctx, String hostname, io.netty5.util.concurrent.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(io.netty5.channel.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, io.netty5.buffer.api.BufferAllocator allocator)
Returns a newSslHandler
using the givenSslContext
andBufferAllocator
. Users may override this method to implement custom behavior.
-
-