Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-2312

Response body from returnContent() truncated to 256 bytes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.3
    • 5.3.1
    • Fluent HC
    • None

    Description

      This is a bug introduced by pull request 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 (200 OK). As a result, returnContent() will only ever return a String from the first 256 bytes.

      This code triggers the bug:

      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());

      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.

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              aspargillus Frank Schimmel
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: