mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-09 09:09:46 +03:00
FileServerHandler update
This commit is contained in:
parent
275305b16c
commit
111ebd2f19
1 changed files with 35 additions and 33 deletions
|
@ -31,6 +31,7 @@
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
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_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
|
||||||
public static final String HTTP_DATE_GMT_TIMEZONE = "GMT";
|
public static final String HTTP_DATE_GMT_TIMEZONE = "GMT";
|
||||||
|
public static final String READ = "r";
|
||||||
public static final int HTTP_CACHE_SECONDS = 60;
|
public static final int HTTP_CACHE_SECONDS = 60;
|
||||||
private final File base;
|
private final Path base;
|
||||||
private final boolean fullOut;
|
private final boolean fullOut;
|
||||||
|
|
||||||
public FileServerHandler(File base, boolean fullOut) {
|
public FileServerHandler(Path base, boolean fullOut) {
|
||||||
this.base = base;
|
this.base = base;
|
||||||
this.fullOut = fullOut;
|
this.fullOut = fullOut;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +77,7 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File file = new File(base, path);
|
File file = base.resolve(path).toFile();
|
||||||
if (file.isHidden() || !file.exists()) {
|
if (file.isHidden() || !file.exists()) {
|
||||||
sendError(ctx, NOT_FOUND);
|
sendError(ctx, NOT_FOUND);
|
||||||
return;
|
return;
|
||||||
|
@ -115,7 +117,7 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr
|
||||||
|
|
||||||
RandomAccessFile raf;
|
RandomAccessFile raf;
|
||||||
try {
|
try {
|
||||||
raf = new RandomAccessFile(file, "r");
|
raf = new RandomAccessFile(file, READ);
|
||||||
} catch (FileNotFoundException ignore) {
|
} catch (FileNotFoundException ignore) {
|
||||||
sendError(ctx, NOT_FOUND);
|
sendError(ctx, NOT_FOUND);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue