public class CorsHandler extends ChannelDuplexHandler
This handler can be configured using a CorsConfig, please
refer to this class for details about the configuration options available.
ChannelHandler.Sharable| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
ANY_ORIGIN |
private CorsConfig |
config |
private static InternalLogger |
logger |
private static java.lang.String |
NULL_ORIGIN |
private HttpRequest |
request |
| Constructor and Description |
|---|
CorsHandler(CorsConfig config)
Creates a new instance with the specified
CorsConfig. |
| Modifier and Type | Method and Description |
|---|---|
void |
channelRead(ChannelHandlerContext ctx,
java.lang.Object msg)
Calls
ChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline. |
private void |
echoRequestOrigin(HttpResponse response) |
private static void |
forbidden(ChannelHandlerContext ctx,
HttpRequest request) |
private void |
handlePreflight(ChannelHandlerContext ctx,
HttpRequest request) |
private static boolean |
isPreflightRequest(HttpRequest request) |
private static void |
respond(ChannelHandlerContext ctx,
HttpRequest request,
HttpResponse response) |
private void |
setAllowCredentials(HttpResponse response) |
private void |
setAllowHeaders(HttpResponse response) |
private void |
setAllowMethods(HttpResponse response) |
private static void |
setAnyOrigin(HttpResponse response) |
private void |
setExposeHeaders(HttpResponse response) |
private void |
setMaxAge(HttpResponse response) |
private static void |
setNullOrigin(HttpResponse response) |
private boolean |
setOrigin(HttpResponse response) |
private static void |
setOrigin(HttpResponse response,
java.lang.String origin) |
private void |
setPreflightHeaders(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 void |
setVaryHeader(HttpResponse response) |
private boolean |
validateOrigin() |
void |
write(ChannelHandlerContext ctx,
java.lang.Object msg,
ChannelPromise promise)
Calls
ChannelOutboundInvoker.write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline. |
bind, close, connect, deregister, disconnect, flush, readchannelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredensureNotSharable, handlerAdded, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexceptionCaught, handlerAdded, handlerRemovedprivate static final InternalLogger logger
private static final java.lang.String ANY_ORIGIN
private static final java.lang.String NULL_ORIGIN
private final CorsConfig config
private HttpRequest request
public CorsHandler(CorsConfig config)
CorsConfig.public void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
ChannelInboundHandlerAdapterChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelRead in interface ChannelInboundHandlerchannelRead in class ChannelInboundHandlerAdapterjava.lang.Exceptionprivate void handlePreflight(ChannelHandlerContext ctx, HttpRequest request)
private void setPreflightHeaders(HttpResponse response)
response - the HttpResponse to which the preflight response headers should be added.private boolean setOrigin(HttpResponse response)
private boolean validateOrigin()
private void echoRequestOrigin(HttpResponse response)
private static void setVaryHeader(HttpResponse response)
private static void setAnyOrigin(HttpResponse response)
private static void setNullOrigin(HttpResponse response)
private static void setOrigin(HttpResponse response, java.lang.String origin)
private void setAllowCredentials(HttpResponse response)
private static boolean isPreflightRequest(HttpRequest request)
private void setExposeHeaders(HttpResponse response)
private void setAllowMethods(HttpResponse response)
private void setAllowHeaders(HttpResponse response)
private void setMaxAge(HttpResponse response)
public void write(ChannelHandlerContext ctx, java.lang.Object msg, ChannelPromise promise) throws java.lang.Exception
ChannelDuplexHandlerChannelOutboundInvoker.write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.write in interface ChannelOutboundHandlerwrite in class ChannelDuplexHandlerctx - the ChannelHandlerContext for which the write operation is mademsg - the message to writepromise - the ChannelPromise to notify once the operation completesjava.lang.Exception - thrown if an error occursprivate static void forbidden(ChannelHandlerContext ctx, HttpRequest request)
private static void respond(ChannelHandlerContext ctx, HttpRequest request, HttpResponse response)