From affc527326f142ed9c1db22d4083eb3d15e0d449 Mon Sep 17 00:00:00 2001 From: heavyrain2012 Date: Fri, 23 Jul 2021 08:28:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=87=E4=BB=B6=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E6=97=B6=E5=87=BA=E7=8E=B0=E7=9A=84=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiaoleilu/loServer/action/FileAction.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/FileAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/FileAction.java index 94940089..9c48c603 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/FileAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/FileAction.java @@ -46,21 +46,28 @@ public class FileAction extends Action { return true; } - final File file = getFileByPath(request.getPath()); - Logger.debug("Client [{}] get file [{}]", request.getIp(), file.getPath()); + File file = null; + try { + file = getFileByPath(request.getPath()); + } catch (Exception e) { + response.sendError(HttpResponseStatus.NOT_FOUND, "404 File not found!"); + return true; + } - // 隐藏文件,跳过 - if (file.isHidden() || !file.exists()) { + // 隐藏文件或不存在,跳过 + if (file == null || file.isHidden() || !file.exists()) { response.sendError(HttpResponseStatus.NOT_FOUND, "404 File not found!"); return true; } // 非文件,跳过 - if (false == file.isFile()) { + if (!file.isFile()) { response.sendError(HttpResponseStatus.FORBIDDEN, "403 Forbidden!"); return true; } + Logger.debug("Client [{}] get file [{}]", request.getIp(), file.getPath()); + // Cache Validation String ifModifiedSince = request.getHeader(HttpHeaderNames.IF_MODIFIED_SINCE.toString()); if (StrUtil.isNotBlank(ifModifiedSince)) {