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

Provide InputStreamBody with contentLength if known

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.5.3
    • 5.0 Alpha2
    • HttpClient (classic)
    • None
    • windows 10 64 bit, oracle jdk 1.8.0_112 64bit

    Description

      When building a multipart request that consists of at least one body where the contentLength is -1 in AbstractMultipartForm#getTotalLength -1 is returned, resulting in a missing Content-Length header in the request. This behaviour is correct.
      But in some cases you know the contentLength of a body part even though it might be streamed.

      To implement this I subclassed org.apache.http.entity.mime.content.InputStreamBody

      public class ContentLengthInputStreamBody extends InputStreamBody {

      private final long contentLength;

      public ContentLengthInputStreamBody(InputStream in, ContentType contentType, String filename, long contentLength )

      { super(in, contentType, filename); this.contentLength = contentLength; }

      @Override
      public long getContentLength()

      { return this.contentLength; }

      }

      I also needed to do this because a foreign HTTP Server, which is not under my control, refused to handle my request when the Content-Length header was not set.

      This might not be a common issue nor is it hard to solve, but you might think of adding this functionality to InputStreamBody itself.

      Attachments

        Activity

          People

            Unassigned Unassigned
            mr_wallace Marcel Thannhäuser
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: