From d748366dfed2926b958cc546516a76094f7c6efa Mon Sep 17 00:00:00 2001 From: Looly Date: Sat, 22 Oct 2022 18:43:43 +0800 Subject: [PATCH] add test --- .../java/cn/hutool/http/HttpResponse.java | 17 ++++++------- .../java/cn/hutool/http/IssueI5WAV4Test.java | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) create mode 100755 hutool-http/src/test/java/cn/hutool/http/IssueI5WAV4Test.java diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpResponse.java b/hutool-http/src/main/java/cn/hutool/http/HttpResponse.java index f0af91e5c..e41e8d2ba 100755 --- a/hutool-http/src/main/java/cn/hutool/http/HttpResponse.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpResponse.java @@ -72,7 +72,6 @@ public class HttpResponse extends HttpBase implements Closeable { * @param isIgnoreBody 是否忽略读取响应体 * @since 3.1.2 */ - @SuppressWarnings("resource") protected HttpResponse(final HttpConnection httpConnection, final HttpConfig config, final Charset charset, final boolean isAsync, final boolean isIgnoreBody) { this.httpConnection = httpConnection; this.config = config; @@ -479,18 +478,15 @@ public class HttpResponse extends HttpBase implements Closeable { * 3、持有Http流,并不关闭流 * * - * @return this * @throws HttpException IO异常 */ - @SuppressWarnings("resource") - private HttpResponse initWithDisconnect() throws HttpException { + private void initWithDisconnect() throws HttpException { try { init(); } catch (final HttpException e) { this.httpConnection.disconnectQuietly(); throw e; } - return this; } /** @@ -503,10 +499,10 @@ public class HttpResponse extends HttpBase implements Closeable { * 3、持有Http流,并不关闭流 * * - * @return this * @throws HttpException IO异常 */ - private HttpResponse init() throws HttpException { + @SuppressWarnings("resource") + private void init() throws HttpException { // 获取响应状态码 try { this.status = httpConnection.responseCode(); @@ -517,7 +513,6 @@ public class HttpResponse extends HttpBase implements Closeable { // 服务器无返回内容,忽略之 } - // 读取响应头信息 try { this.headers = httpConnection.headers(); @@ -526,6 +521,7 @@ public class HttpResponse extends HttpBase implements Closeable { // StaticLog.warn(e, e.getMessage()); } + // 存储服务端设置的Cookie信息 GlobalCookieManager.store(httpConnection, this.headers); @@ -540,7 +536,9 @@ public class HttpResponse extends HttpBase implements Closeable { this.in = new HttpInputStream(this); // 同步情况下强制同步 - return this.isAsync ? this : forceSync(); + if (!this.isAsync) { + forceSync(); + } } /** @@ -641,6 +639,5 @@ public class HttpResponse extends HttpBase implements Closeable { } return fileName; } - // ---------------------------------------------------------------- Private method end } diff --git a/hutool-http/src/test/java/cn/hutool/http/IssueI5WAV4Test.java b/hutool-http/src/test/java/cn/hutool/http/IssueI5WAV4Test.java new file mode 100755 index 000000000..1bef9bfca --- /dev/null +++ b/hutool-http/src/test/java/cn/hutool/http/IssueI5WAV4Test.java @@ -0,0 +1,24 @@ +package cn.hutool.http; + +import cn.hutool.json.JSONUtil; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +public class IssueI5WAV4Test { + + @Test + @Ignore + public void getTest(){ + //测试代码 + final Map map = new HashMap<>(); + map.put("taskID", 370); + map.put("flightID", 2879); + + + final String body = HttpRequest.get("http://localhost:8884/api/test/testHttpUtilGetWithBody").body(JSONUtil.toJsonStr(map)).execute().body(); + System.out.println("使用hutool返回结果:" + body); + } +}