Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
youfanx committed Sep 15, 2023
1 parent 5a9bf4e commit 77e70ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion rxlib/src/main/java/org/rx/io/MemoryStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ public MemoryStream(@NonNull ByteBuf buf, boolean forWrite) {

@Override
protected void freeObjects() {
buffer.release();
if (buffer != null) {
buffer.release();
}
}

@Override
Expand Down
15 changes: 9 additions & 6 deletions rxlib/src/main/java/org/rx/net/http/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,16 @@ public String getResponseText() {
}

@JSONField(serialize = false)
public Headers getHeaders() {
public Charset getCharset() {
return response.body() != null ? Reflects.invokeMethod(response.body(), "charset") : StandardCharsets.UTF_8;
}

public Headers responseHeaders() {
return response.headers();
}

@JSONField(serialize = false)
public Charset getCharset() {
return Reflects.invokeMethod(response.body(), "charset");
public InputStream responseStream() {
return response.body() != null ? response.body().byteStream() : null;
}

@SneakyThrows
Expand Down Expand Up @@ -619,13 +622,13 @@ public RequestBody toBody() {
ResponseContent resContent = new ResponseContent(getClient().newCall(createRequest(forwardUrl).method(servletRequest.getMethod(), reqContent.toBody()).build()).execute());
resContent.cachingStream = cachingStream;
servletResponse.setStatus(resContent.response.code());
for (Pair<? extends String, ? extends String> header : resContent.getHeaders()) {
for (Pair<? extends String, ? extends String> header : resContent.responseHeaders()) {
servletResponse.setHeader(header.getFirst(), header.getSecond());
}

ResponseBody responseBody = resContent.response.body();
boolean hasResBody = responseBody != null;
log.info("Forward response: {}\nheaders: {} hasBody: {}", resContent.getResponseUrl(), toJsonString(resContent.getHeaders()), hasResBody);
log.info("Forward response: {}\nheaders: {} hasBody: {}", resContent.getResponseUrl(), toJsonString(resContent.responseHeaders()), hasResBody);
if (hasResBody) {
MediaType responseContentType = responseBody.contentType();
if (responseContentType != null) {
Expand Down

0 comments on commit 77e70ef

Please sign in to comment.