hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Kalnichevski (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (HTTPCLIENT-1832) Provide InputStreamBody with contentLength if known
Date Mon, 20 Mar 2017 13:48:41 GMT

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

Oleg Kalnichevski resolved HTTPCLIENT-1832.
-------------------------------------------
       Resolution: Fixed
    Fix Version/s: 5.0 Alpha2
                   4.6 Alpha1

Implemented in SVN trunk and 4.6.x branch. 

Please review and close.

Oleg

> Provide InputStreamBody with contentLength if known
> ---------------------------------------------------
>
>                 Key: HTTPCLIENT-1832
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1832
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpClient (classic)
>    Affects Versions: 4.5.3
>         Environment: windows 10 64 bit, oracle jdk 1.8.0_112 64bit
>            Reporter: Marcel Thannhäuser
>             Fix For: 4.6 Alpha1, 5.0 Alpha2
>
>
> 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.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

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


Mime
View raw message