FileServerHandler update

This commit is contained in:
Gravit 2018-10-02 19:20:57 +07:00
parent 275305b16c
commit 111ebd2f19

View file

@ -31,6 +31,7 @@
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@ -47,11 +48,12 @@ public class FileServerHandler extends SimpleChannelInboundHandler<FullHttpReque
public static final String HTTP_DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
public static final String HTTP_DATE_GMT_TIMEZONE = "GMT";
public static final String READ = "r";
public static final int HTTP_CACHE_SECONDS = 60;
private final File base;
private final Path base;
private final boolean fullOut;
public FileServerHandler(File base, boolean fullOut) {
public FileServerHandler(Path base, boolean fullOut) {
this.base = base;
this.fullOut = fullOut;
}
@ -75,7 +77,7 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr
return;
}
File file = new File(base, path);
File file = base.resolve(path).toFile();
if (file.isHidden() || !file.exists()) {
sendError(ctx, NOT_FOUND);
return;
@ -115,7 +117,7 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr
RandomAccessFile raf;
try {
raf = new RandomAccessFile(file, "r");
raf = new RandomAccessFile(file, READ);
} catch (FileNotFoundException ignore) {
sendError(ctx, NOT_FOUND);
return;