Skip to content

Commit

Permalink
test: 安全响应流处理接口
Browse files Browse the repository at this point in the history
  • Loading branch information
mySingleLive committed Dec 17, 2024
1 parent e803b94 commit e0f8ec3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4086,7 +4086,12 @@ public ForestRequest<T> retryWhen(Class<? extends RetryWhen> conditionClass) {
public boolean isDownloadFile() {
return isDownloadFile;
}


/**
* 该请求是否以流的方式接受数据
*
* @return {@code true}: 流的方式,{@code false}: 非流的方式
*/
public boolean isReceiveStream() {
if (isDownloadFile()) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public ResultGetter openStream(BiConsumer<InputStream, ForestResponse> consumer)
consumer.accept(in, response);
} catch (Exception e) {
throw new ForestRuntimeException(e);
} finally {
response.close();
}
return this;
}
Expand All @@ -142,6 +144,8 @@ public <R> R openStream(BiFunction<InputStream, ForestResponse, R> function) {
return (R) ret;
} catch (Exception e) {
throw new ForestRuntimeException(e);
} finally {
response.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,7 @@ public void testRequest_get_return_map_list() {
public void testRequest_get_return_response() {
server.enqueue(new MockResponse().setBody("{\"a\": 1, \"b\": 2, \"c\": 3}"));
ForestResponse<Map<String, Object>> response = Forest.get("http://localhost:{}", server.getPort())
.execute(new TypeReference<ForestResponse<Map<String, Object>>>() {
});
.execute(new TypeReference<ForestResponse<Map<String, Object>>>() {});
assertThat(response).isNotNull();
Map<String, Object> result = response.getResult();
assertThat(result).isNotNull();
Expand Down

0 comments on commit e0f8ec3

Please sign in to comment.