You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Saminda Abeyruwan <sa...@opensource.lk> on 2005/08/24 05:28:48 UTC

Calculation of Content Lenght by RequestEntity's getContentLength() method

Hi,

Would someone pls be kind enough to tell me, if a MIME message being 
added to POST body, and if not "chunked" and  "keep-alive" is present, 
would getContentLength() give the correct "Content-Lenght". I heard that 
this method would return if the body is String. Pls acknowledge.

Saminda

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


Re: Calculation of Content Lenght by RequestEntity's getContentLength() method

Posted by Roland Weber <RO...@de.ibm.com>.
Hi Saminda,

> Thanx for the quike reply. Let assume i'm sending a MTOM message in 
> POST. When chunking is -1, i am forced to give "Content-Length" header 
> parameter value, if "keep-alive" is ON. In that case Request Entity 
> calls xxx.getContentLenght(). Would this content-length value be 
> correct, if MTOM message is contain 1 Mb of data.

I don't know what you mean with "MTOM" message. Also, you don't have
to give a Content-Length header. The method will automatically add it,
provided that you told HttpClient not to use chunked encoding and that
the request entity is able to compute the content length.
As a general rule, if all elements of the request entity are in memory,
it can compute the content length. If one of the elements is a stream,
it can not.

If you have to send a stream, you can still implement your own
RequestEntity, or PartSource, to provide the required input for
computing the content length.

I suggest you just implement it, and tell us if the content length is
not computed. If that should be the case, we'll help you with the
details. It is hard to give you an exact answer without knowing what
exactly you want to do. But rest assured, if your application has all
the data it needs to compute the content length, we'll find a way for
you to get that length into the HTTP request :-)

hope that helps,
  Roland


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


Re: Calculation of Content Lenght by RequestEntity's getContentLength() method

Posted by Saminda Abeyruwan <sa...@opensource.lk>.
Hi Roland,

Thanx for the quike reply. Let assume i'm sending a MTOM message in 
POST. When chunking is -1, i am forced to give "Content-Length" header 
parameter value, if "keep-alive" is ON. In that case Request Entity 
calls xxx.getContentLenght(). Would this content-length value be 
correct, if MTOM message is contain 1 Mb of data.

Saminda

Roland Weber wrote:

>Hello Saminda,
>
>  
>
>>Would someone pls be kind enough to tell me, if a MIME message being 
>>added to POST body, and if not "chunked" and  "keep-alive" is present, 
>>would getContentLength() give the correct "Content-Lenght".
>>    
>>
>
>The request entity does not know of the presence of a chunked encoding.
>It determines the content length based on the data you put into the
>request entity, and it returns -1 (or something like that) if it can
>not determine the content length. In that case, chunked encoding will
>be chosen by the POST method.
>If the request entity is able to compute the content length, then
>RE.getContentLength will return it. If the request entity is unable
>to compute the content length, there is no way you can force it.
>
>  
>
>>I heard that 
>>this method would return if the body is String. Pls acknowledge.
>>    
>>
>
>Sorry, you lost me there. If only strings are contained in the request
>entity, then it should be able to compute the content length. Is that
>what you meant?
>
>hope that helps,
>  Roland
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
>
>
>
>  
>


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


Re: Calculation of Content Lenght by RequestEntity's getContentLength() method

Posted by Roland Weber <RO...@de.ibm.com>.
Hello Saminda,

> Would someone pls be kind enough to tell me, if a MIME message being 
> added to POST body, and if not "chunked" and  "keep-alive" is present, 
> would getContentLength() give the correct "Content-Lenght".

The request entity does not know of the presence of a chunked encoding.
It determines the content length based on the data you put into the
request entity, and it returns -1 (or something like that) if it can
not determine the content length. In that case, chunked encoding will
be chosen by the POST method.
If the request entity is able to compute the content length, then
RE.getContentLength will return it. If the request entity is unable
to compute the content length, there is no way you can force it.

> I heard that 
> this method would return if the body is String. Pls acknowledge.

Sorry, you lost me there. If only strings are contained in the request
entity, then it should be able to compute the content length. Is that
what you meant?

hope that helps,
  Roland


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