Skip to content

Commit e0f8ec3

Browse files
committedDec 17, 2024
test: 安全响应流处理接口
·
v1.7.3v1.6.0
1 parent e803b94 commit e0f8ec3

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed
 

‎forest-core/src/main/java/com/dtflys/forest/http/ForestRequest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4086,7 +4086,12 @@ public ForestRequest<T> retryWhen(Class<? extends RetryWhen> conditionClass) {
40864086
public boolean isDownloadFile() {
40874087
return isDownloadFile;
40884088
}
4089-
4089+
4090+
/**
4091+
* 该请求是否以流的方式接受数据
4092+
*
4093+
* @return {@code true}: 流的方式,{@code false}: 非流的方式
4094+
*/
40904095
public boolean isReceiveStream() {
40914096
if (isDownloadFile()) {
40924097
return true;

‎forest-core/src/main/java/com/dtflys/forest/http/ResultGetter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ public ResultGetter openStream(BiConsumer<InputStream, ForestResponse> consumer)
119119
consumer.accept(in, response);
120120
} catch (Exception e) {
121121
throw new ForestRuntimeException(e);
122+
} finally {
123+
response.close();
122124
}
123125
return this;
124126
}
@@ -142,6 +144,8 @@ public <R> R openStream(BiFunction<InputStream, ForestResponse, R> function) {
142144
return (R) ret;
143145
} catch (Exception e) {
144146
throw new ForestRuntimeException(e);
147+
} finally {
148+
response.close();
145149
}
146150
}
147151

‎forest-core/src/test/java/com/dtflys/forest/test/TestGenericForestClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,7 @@ public void testRequest_get_return_map_list() {
991991
public void testRequest_get_return_response() {
992992
server.enqueue(new MockResponse().setBody("{\"a\": 1, \"b\": 2, \"c\": 3}"));
993993
ForestResponse<Map<String, Object>> response = Forest.get("http://localhost:{}", server.getPort())
994-
.execute(new TypeReference<ForestResponse<Map<String, Object>>>() {
995-
});
994+
.execute(new TypeReference<ForestResponse<Map<String, Object>>>() {});
996995
assertThat(response).isNotNull();
997996
Map<String, Object> result = response.getResult();
998997
assertThat(result).isNotNull();

0 commit comments

Comments
 (0)
Please sign in to comment.