Package io.netty.handler.codec.http.cors
Class CorsHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.netty.handler.codec.http.cors.CorsHandler
- All Implemented Interfaces:
ChannelHandler,ChannelInboundHandler,ChannelOutboundHandler
Handles Cross Origin Resource Sharing (CORS) requests.
This handler can be configured using one or more CorsConfig, please
refer to this class for details about the configuration options available.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate CorsConfigprivate final List<CorsConfig> private booleanprivate final booleanprivate static final InternalLoggerprivate static final Stringprivate HttpRequest -
Constructor Summary
ConstructorsConstructorDescriptionCorsHandler(CorsConfig config) Creates a new instance with a singleCorsConfig.CorsHandler(List<CorsConfig> configList, boolean isShortCircuit) Creates a new instance with the specified config list. -
Method Summary
Modifier and TypeMethodDescriptionvoidchannelRead(ChannelHandlerContext ctx, Object msg) CallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.private voidechoRequestOrigin(HttpResponse response) private static voidforbidden(ChannelHandlerContext ctx, HttpRequest request) private CorsConfiggetForOrigin(String requestOrigin) private voidhandlePreflight(ChannelHandlerContext ctx, HttpRequest request) private static booleanisPreflightRequest(HttpRequest request) private static voidrespond(ChannelHandlerContext ctx, HttpRequest request, HttpResponse response) private voidsetAllowCredentials(HttpResponse response) private voidsetAllowHeaders(HttpResponse response) private voidsetAllowMethods(HttpResponse response) private voidsetAllowPrivateNetwork(HttpResponse response) private static voidsetAnyOrigin(HttpResponse response) private voidsetExposeHeaders(HttpResponse response) private voidsetMaxAge(HttpResponse response) private static voidsetNullOrigin(HttpResponse response) private booleansetOrigin(HttpResponse response) private static voidsetOrigin(HttpResponse response, String origin) private voidsetPreflightHeaders(HttpResponse response) This is a non CORS specification feature which enables the setting of preflight response headers that might be required by intermediaries.private static voidsetVaryHeader(HttpResponse response) voidwrite(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) CallsChannelOutboundInvoker.write(Object, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, readMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Field Details
-
logger
-
ANY_ORIGIN
- See Also:
-
NULL_ORIGIN
- See Also:
-
config
-
request
-
configList
-
isShortCircuit
private final boolean isShortCircuit -
consumeContent
private boolean consumeContent
-
-
Constructor Details
-
CorsHandler
Creates a new instance with a singleCorsConfig. -
CorsHandler
Creates a new instance with the specified config list. If more than one config matches a certain origin, the first in the List will be used.- Parameters:
configList- List ofCorsConfigisShortCircuit- Same asCorsConfig.isShortCircuit()but applicable to all supplied configs.
-
-
Method Details
-
channelRead
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelReadin interfaceChannelInboundHandler- Overrides:
channelReadin classChannelInboundHandlerAdapter- Throws:
Exception
-
handlePreflight
-
setPreflightHeaders
This is a non CORS specification feature which enables the setting of preflight response headers that might be required by intermediaries.- Parameters:
response- the HttpResponse to which the preflight response headers should be added.
-
getForOrigin
-
setOrigin
-
echoRequestOrigin
-
setVaryHeader
-
setAnyOrigin
-
setNullOrigin
-
setOrigin
-
setAllowCredentials
-
isPreflightRequest
-
setExposeHeaders
-
setAllowMethods
-
setAllowHeaders
-
setMaxAge
-
setAllowPrivateNetwork
-
write
Description copied from class:ChannelDuplexHandlerCallsChannelOutboundInvoker.write(Object, ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
writein interfaceChannelOutboundHandler- Overrides:
writein classChannelDuplexHandler- Parameters:
ctx- theChannelHandlerContextfor which the write operation is mademsg- the message to writepromise- theChannelPromiseto notify once the operation completes- Throws:
Exception- thrown if an error occurs
-
forbidden
-
respond
-