From 7116177225b6f3261cc0fd72fda9af1663e31e0a Mon Sep 17 00:00:00 2001 From: Looly Date: Thu, 10 Feb 2022 00:17:25 +0800 Subject: [PATCH] fix bug --- CHANGELOG.md | 3 ++- .../java/cn/hutool/http/server/HttpServerBase.java | 11 ++++++++++- .../cn/hutool/http/server/handler/ActionHandler.java | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6686d2456..58601987e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ # 🚀Changelog ------------------------------------------------------------------------------------------------------------- -# 5.7.21 (2022-02-07) +# 5.7.21 (2022-02-10) ### 🐣新特性 * 【extra 】 增加jetbrick模板支持 @@ -24,6 +24,7 @@ * 【extra 】 修复EmojiUtil.toHtmlHex()方法(pr#519@Gitee) * 【system 】 修复CpuInfo.getUsed()方法(issue#2116@Github) * 【dfa 】 修复密集匹配和贪婪匹配冲突问题(issue#2126@Github) +* 【http 】 修复Action中HttpExchange没有关闭问题 ------------------------------------------------------------------------------------------------------------- # 5.7.20 (2022-01-20) diff --git a/hutool-http/src/main/java/cn/hutool/http/server/HttpServerBase.java b/hutool-http/src/main/java/cn/hutool/http/server/HttpServerBase.java index 3c2b62fc5..ab0ba5920 100644 --- a/hutool-http/src/main/java/cn/hutool/http/server/HttpServerBase.java +++ b/hutool-http/src/main/java/cn/hutool/http/server/HttpServerBase.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.CharsetUtil; import com.sun.net.httpserver.HttpContext; import com.sun.net.httpserver.HttpExchange; +import java.io.Closeable; import java.nio.charset.Charset; /** @@ -12,7 +13,7 @@ import java.nio.charset.Charset; * @author looly * @since 5.2.6 */ -public class HttpServerBase { +public class HttpServerBase implements Closeable { final static Charset DEFAULT_CHARSET = CharsetUtil.CHARSET_UTF_8; @@ -45,4 +46,12 @@ public class HttpServerBase { public HttpContext getHttpContext() { return getHttpExchange().getHttpContext(); } + + /** + * 调用{@link HttpExchange#close()},关闭请求流和响应流 + */ + @Override + public void close() { + this.httpExchange.close(); + } } diff --git a/hutool-http/src/main/java/cn/hutool/http/server/handler/ActionHandler.java b/hutool-http/src/main/java/cn/hutool/http/server/handler/ActionHandler.java index 940a2c980..42f88c548 100644 --- a/hutool-http/src/main/java/cn/hutool/http/server/handler/ActionHandler.java +++ b/hutool-http/src/main/java/cn/hutool/http/server/handler/ActionHandler.java @@ -33,5 +33,6 @@ public class ActionHandler implements HttpHandler { new HttpServerRequest(httpExchange), new HttpServerResponse(httpExchange) ); + httpExchange.close(); } }