@ChannelHandler.Sharable public class StaticFileServerHandler<T extends RestfulGateway> extends RedirectHandler<T>
This code is based on the "HttpStaticFileServerHandler" from the Netty project's HTTP server example.
Modifier and Type | Field and Description |
---|---|
static String |
HTTP_DATE_FORMAT
Date format for HTTP.
|
leaderRetriever, localAddressFuture, logger, responseHeaders, timeout
Constructor and Description |
---|
StaticFileServerHandler(GatewayRetriever<? extends T> retriever,
CompletableFuture<String> localJobManagerAddressFuture,
Time timeout,
File rootPath) |
Modifier and Type | Method and Description |
---|---|
void |
exceptionCaught(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx,
Throwable cause) |
protected void |
respondAsLeader(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext channelHandlerContext,
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.router.Routed routed,
T gateway) |
static void |
sendError(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx,
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus status)
Writes a simple error response message.
|
static void |
sendNotModified(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx)
Send the "304 Not Modified" response.
|
static void |
setContentTypeHeader(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse response,
File file)
Sets the content type header for the HTTP Response.
|
static void |
setDateAndCacheHeaders(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse response,
File fileToCache)
Sets the "date" and "cache" headers for the HTTP Response.
|
static void |
setDateHeader(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse response)
Sets the "date" header for the HTTP response.
|
channelRead0
acceptInboundMessage, channelRead
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
handlerAdded, handlerRemoved, isSharable
public static final String HTTP_DATE_FORMAT
public StaticFileServerHandler(GatewayRetriever<? extends T> retriever, CompletableFuture<String> localJobManagerAddressFuture, Time timeout, File rootPath) throws IOException
IOException
protected void respondAsLeader(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext channelHandlerContext, org.apache.flink.shaded.netty4.io.netty.handler.codec.http.router.Routed routed, T gateway) throws Exception
respondAsLeader
in class RedirectHandler<T extends RestfulGateway>
Exception
public void exceptionCaught(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
exceptionCaught
in interface org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler
exceptionCaught
in interface org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler
exceptionCaught
in class org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandlerAdapter
public static void sendError(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx, org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus status)
ctx
- The channel context to write the response to.status
- The response status.public static void sendNotModified(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext ctx)
ctx
- The channel context to write the response to.public static void setDateHeader(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse response)
response
- HTTP responsepublic static void setDateAndCacheHeaders(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse response, File fileToCache)
response
- The HTTP response object.fileToCache
- File to extract the modification timestamp from.public static void setContentTypeHeader(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse response, File file)
response
- HTTP responsefile
- file to extract content typeCopyright © 2014–2019 The Apache Software Foundation. All rights reserved.