From 2c810d92bff9043a2bf4b11e468b7b47c7d36f8a Mon Sep 17 00:00:00 2001 From: Looly <loolly@aliyun.com> Date: Mon, 3 Mar 2025 11:09:10 +0800 Subject: [PATCH] =?UTF-8?q?`HttpBase`=E5=A2=9E=E5=8A=A0=E9=87=8D=E8=BD=BD?= =?UTF-8?q?=E5=8F=AF=E9=80=89=E6=98=AF=E5=90=A6=E8=BF=94=E5=9B=9E=E5=A3=B0?= =?UTF-8?q?=E8=B0=83=EF=BC=88pr#3883@Github=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 + .../main/java/cn/hutool/http/HttpBase.java | 2 + .../java/cn/hutool/http/HttpConnection.java | 1 + .../java/cn/hutool/http/HttpRequestTest.java | 1 + .../java/cn/hutool/http/SimpleHttpServer.java | 81 ------------------- 5 files changed, 6 insertions(+), 81 deletions(-) delete mode 100644 hutool-http/src/test/java/cn/hutool/http/SimpleHttpServer.java diff --git a/CHANGELOG.md b/CHANGELOG.md index e742f0230..875908f76 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ * 【json 】 ObjectMapper删除重复trim(pr#3859@Github) * 【core 】 `FileWriter`增加方法,可选是否追加换行符(issue#3858@Github) * 【core 】 `IdcardUtil`验证10位身份证兼容中英文括号(issue#IBP6T1@Gitee) +* 【extra 】 `PinyinUtil`增加重载可选是否返回声调(pr#3875@Github) +* 【http 】 `HttpBase`增加重载可选是否返回声调(pr#3883@Github) ### 🐞Bug修复 * 【setting】 修复`SettingLoader`load未抛出异常导致配置文件无法正常遍历的问题(pr#3868@Github) diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpBase.java b/hutool-http/src/main/java/cn/hutool/http/HttpBase.java index 8877962d7..894d0cf78 100644 --- a/hutool-http/src/main/java/cn/hutool/http/HttpBase.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpBase.java @@ -286,6 +286,7 @@ public abstract class HttpBase<T> { * * @param aggregate 是否需要聚合 * @return this + * @since 5.8.37 */ public T headerAggregation(boolean aggregate) { this.isHeaderAggregated = aggregate; @@ -296,6 +297,7 @@ public abstract class HttpBase<T> { * 获取是否需要聚合请求头状态 * * @return isHeaderAggregated 请求头聚合状态 + * @since 5.8.37 */ public boolean isHeaderAggregated() { return isHeaderAggregated; diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpConnection.java b/hutool-http/src/main/java/cn/hutool/http/HttpConnection.java index 456714f76..1e712691f 100644 --- a/hutool-http/src/main/java/cn/hutool/http/HttpConnection.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpConnection.java @@ -237,6 +237,7 @@ public class HttpConnection { * @param isOverride 是否覆盖 * @param isHeaderAggregated 是否聚合 * @return this + * @since 5.8.37 */ public HttpConnection header(Map<String, List<String>> headerMap, boolean isOverride, boolean isHeaderAggregated) { if (!isHeaderAggregated){ diff --git a/hutool-http/src/test/java/cn/hutool/http/HttpRequestTest.java b/hutool-http/src/test/java/cn/hutool/http/HttpRequestTest.java index eec10a075..4394d6bbf 100644 --- a/hutool-http/src/test/java/cn/hutool/http/HttpRequestTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/HttpRequestTest.java @@ -272,6 +272,7 @@ public class HttpRequestTest { } @Test + @Disabled public void testHttpHead(){ Map<String,String> map = new HashMap<>(); map.put("test","test"); diff --git a/hutool-http/src/test/java/cn/hutool/http/SimpleHttpServer.java b/hutool-http/src/test/java/cn/hutool/http/SimpleHttpServer.java deleted file mode 100644 index 8c0dc95ad..000000000 --- a/hutool-http/src/test/java/cn/hutool/http/SimpleHttpServer.java +++ /dev/null @@ -1,81 +0,0 @@ -package cn.hutool.http; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.ServerSocket; -import java.net.Socket; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; - -/** - * 一个简单的http服务器示例代码; - * 用于打印出接收到的请求头和简单的post-json的请求体数据来测试 - * - * @author ZhangWeinan - * @date 2025/2/23 15:32 - */ -public class SimpleHttpServer { - - public static void main(String[] args) throws IOException { - int port = 8080; - ServerSocket serverSocket = new ServerSocket(port); - System.out.println("Server started on port " + port); - - while (true) { - Socket clientSocket = serverSocket.accept(); - new Thread(() -> handleClient(clientSocket)).start(); - } - } - - private static void handleClient(Socket clientSocket) { - try (BufferedReader in = new BufferedReader( - new InputStreamReader(clientSocket.getInputStream())); - OutputStream out = clientSocket.getOutputStream()) { - String requestLine = in.readLine(); - if (requestLine == null) return; - - String[] parts = requestLine.split(" "); - String method = parts[0]; - - Map<String, String> headers = new HashMap<>(); - String line; - System.out.println("\n=== Headers ==="); - while (!(line = in.readLine()).isEmpty()) { - int colonIndex = line.indexOf(':'); - if (colonIndex > 0) { - String key = line.substring(0, colonIndex).trim(); - String value = line.substring(colonIndex + 1).trim(); - headers.put(key, value); - System.out.println(key + ": " + value); - } - } - if ("POST".equalsIgnoreCase(method)) { - int contentLength = Integer.parseInt(headers.getOrDefault("Content-Length", "0")); - if (contentLength > 0) { - char[] body = new char[contentLength]; - in.read(body, 0, contentLength); - String jsonBody = new String(body); - System.out.println("\n=== JSON Body ==="); - System.out.println(jsonBody); - } - } - String response = "HTTP/1.1 200 OK\r\n" + - "Content-Type: text/plain\r\n" + - "Content-Length: 16\r\n\r\n" + - "Request received"; - out.write(response.getBytes(StandardCharsets.UTF_8)); - - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - clientSocket.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } -}