[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-2312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Frank Schimmel updated HTTPCLIENT-2312:
---------------------------------------
    Description: 
This is a bug introduced by [pull request 
423|https://github.com/apache/httpcomponents-client/pull/423] addressing 
HTTPCLIENT-1756.

The solution for better logging includes the beginning of the response body in 
the exception. Unfortunately, this also impacts the response body in _all_ 
cases, even on success case (200 OK). As a result, returnContent() will only 
ever return a String from the first 256 bytes.

This code triggers the bug:

 
{code:java}
final String jsonResponse = 
Request.get("https://www.neowsapp.com/rest/v1/feed/today";)
        .execute()
        .returnContent().asString();
System.out.println(jsonResponse);
System.out.println(jsonResponse.length());{code}
The problem occurs in the overriding ContentResponseHandler#handleResponse() 
method. It extracts the response body into a byte array, limiting the length to 
MAX_MESSAGE_LENGTH (which is 256).

A better solution would be to modify the overridden method of 
AbstractHttpClientResponseHandler and add the truncated body to the exception 
thrown there instead of just consuming the response body entity.

 

  was:
This is a but introduced by [pull request 
423|https://github.com/apache/httpcomponents-client/pull/423] addressing 
HTTPCLIENT-1756.

The solution for better logging includes the beginning of the response body in 
the exception. Unfortunately, this also impacts the response body in _all_ 
cases, even on success case (200 OK). As a result, returnContent() will only 
ever return a String from the first 256 bytes.

This code triggers the bug:

 
{code:java}
final String jsonResponse = 
Request.get("https://www.neowsapp.com/rest/v1/feed/today";)
        .execute()
        .returnContent().asString();
System.out.println(jsonResponse);
System.out.println(jsonResponse.length());{code}
The problem occurs in the overriding ContentResponseHandler#handleResponse() 
method. It extracts the response body into a byte array, limiting the length to 
MAX_MESSAGE_LENGTH (which is 256).

A better solution would be to modify the overridden method of 
AbstractHttpClientResponseHandler and add the truncated body to the exception 
thrown there instead of just consuming the response body entity.

 


> Response body from returnContent() truncated to 256 bytes
> ---------------------------------------------------------
>
>                 Key: HTTPCLIENT-2312
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2312
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: Fluent HC
>    Affects Versions: 5.3
>            Reporter: Frank Schimmel
>            Priority: Critical
>
> This is a bug introduced by [pull request 
> 423|https://github.com/apache/httpcomponents-client/pull/423] addressing 
> HTTPCLIENT-1756.
> The solution for better logging includes the beginning of the response body 
> in the exception. Unfortunately, this also impacts the response body in _all_ 
> cases, even on success case (200 OK). As a result, returnContent() will only 
> ever return a String from the first 256 bytes.
> This code triggers the bug:
>  
> {code:java}
> final String jsonResponse = 
> Request.get("https://www.neowsapp.com/rest/v1/feed/today";)
>         .execute()
>         .returnContent().asString();
> System.out.println(jsonResponse);
> System.out.println(jsonResponse.length());{code}
> The problem occurs in the overriding ContentResponseHandler#handleResponse() 
> method. It extracts the response body into a byte array, limiting the length 
> to MAX_MESSAGE_LENGTH (which is 256).
> A better solution would be to modify the overridden method of 
> AbstractHttpClientResponseHandler and add the truncated body to the exception 
> thrown there instead of just consuming the response body entity.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to