From a67980d23f9e2d27345fd12e7a889f4cc52695f7 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期一, 25 三月 2024 13:36:50 +0800 Subject: [PATCH] 2024年03月25日13:24:47 --- app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java b/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java index d215b1a..208556b 100644 --- a/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java +++ b/app/src/main/java/com/hdl/photovoltaic/internet/HttpServer/MyNanoHttpServer.java @@ -25,7 +25,7 @@ public class MyNanoHttpServer extends NanoHTTPD { //澹版槑鏈嶅姟绔� 绔彛 - public static final Integer HTTP_PORT = 49152; + public static Integer HTTP_PORT = 49152;// 46219; public MyNanoHttpServer(String hostname, int port) { super(hostname, port); @@ -44,6 +44,7 @@ } return myNanoHttpServer; } + @Override public Response serve(IHTTPSession session) { @@ -78,30 +79,37 @@ //椹卞姩鍗囩骇鏂囦欢璺緞 String fileName = ((HTTPSession) session).getUri(); if (!TextUtils.isEmpty(fileName)) { - if (fileName.contains(HdlFileLogic.getInstance().getDriveRootPath())) { + if (fileName.contains(HdlFileLogic.getInstance().getDriveRootPath()) + || fileName.contains(HdlFileLogic.getInstance().getFirmwareRootPath())) { String range = session.getHeaders().get("range"); if (TextUtils.isEmpty(range)) { return newFixedLengthResponse("閿欒,澶撮儴娌℃湁range瀛楁(-500)"); } - if (range.contains("=")) { + HdlLogLogic.print("http閫嗗彉鍣ㄨ姹�===璇锋眰澶у皬-->" + range, true); + if (!range.contains("=")) { + HdlLogLogic.print("閿欒,range鐨剉alue鏍煎紡涓嶅.(-501)", true); return newFixedLengthResponse("閿欒,range鐨剉alue鏍煎紡涓嶅.(-501)"); } String[] bytesAry = range.split("="); if (bytesAry.length < 2) { + HdlLogLogic.print("閿欒,range鐨剉alue鏍煎紡涓嶅.(-502)", true); return newFixedLengthResponse("閿欒,range鐨剉alue鏍煎紡涓嶅.(-502)"); } String[] dataIndex = bytesAry[1].split("-"); if (dataIndex.length < 2) { + HdlLogLogic.print("閿欒,range鐨剉alue鏍煎紡涓嶅.(-503)", true); return newFixedLengthResponse("閿欒,range鐨剉alue鏍煎紡涓嶅.(-503)"); } int startIndex = Integer.parseInt(dataIndex[0]); int endIndex = Integer.parseInt(dataIndex[1]); if (endIndex + 1 - startIndex <= 0) { + HdlLogLogic.print("閿欒,璇锋眰澶у皬鏈夐棶棰�.(-504)", true); return newFixedLengthResponse("閿欒,璇锋眰澶у皬鏈夐棶棰�.(-504)"); } //璇诲彇鏈湴鏂囦欢瀛楄妭娴� byte[] sourceDataByte = HdlFileLogic.getInstance().readFileByte(fileName); if (sourceDataByte == null || sourceDataByte.length == 0) { + HdlLogLogic.print("閿欒,鏈湴鎵句笉鍒版枃浠�,璇蜂笅杞藉啀璇�.(-505)", true); return newFixedLengthResponse("閿欒,鏈湴鎵句笉鍒版枃浠�,璇蜂笅杞藉啀璇�.(-505)"); } //鏍规嵁璇锋眰澶у皬鍒涘缓缂撳瓨鍖� -- Gitblit v1.8.0