hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: EntityTemplate.setChunked() ignored?
Date Tue, 24 Feb 2009 14:20:00 GMT
On Tue, 2009-02-24 at 12:59 +0000, Florent Georges wrote:
> Oleg Kalnichevski wrote:
> > On Mon, 2009-02-23 at 15:59 +0000, Florent Georges wrote:
> 
> > >   I have the following piece of code, where I create a
> > POST
> > > request, based on the class StringProducer, a simple
> > > implementation of ContentProducer that output a string
> > (see
> > > below):
> > > 
> > >     // the request entity
> > >     ContentProducer prod = new
> > StringProducer(content);
> > >     EntityTemplate entity = new EntityTemplate(prod);
> > >     entity.setChunked(false);
> > > 
> > >     // the POST method, with the above entity
> > >     HttpPost post = new HttpPost(uri);
> > >     post.setEntity(entity);
> > >     client.execute(post);
> > > 
> > >   StringProducer is simply:
> > > 
> > >     private static class StringProducer
> > >             implements ContentProducer
> > >     {
> > >         public StringProducer(String content) {
> > >             myContent = content;
> > >         }
> > >         @Override
> > >         public void writeTo(OutputStream out) throws
> > IOException {
> > >             out.write(myContent.getBytes());
> > >         }
> > >         private String myContent;
> > >     }
> > > 
> > >   Note the following statement above:
> > > 
> > >     entity.setChunked(false);
> > > 
> > >   But in the logs, I get the following:
> > > 
> > >     [DEBUG] wire - >> "POST *****
> > HTTP/1.1[EOL]"
> > >     [DEBUG] wire - >> "Transfer-Encoding:
> > chunked[EOL]"
> > >     [DEBUG] wire - >> ...
> > > 
> > >   Is that normal?
> 
> > Yes, it is. This is perfectly normal. If content length of
> > a request entity is not known, the only way to transfer it
> > is by using chunk coding.
> 
> > Why do not you simply use ByteArrayEntity?
> 
>   Because that's only a simple, reproducible example.  The real code set the output stream
as the destination of the serializer of an XSLT transform.  Of course I could bufferize this
output first, but this is a waste of resources.
> 
>   Regards,
> 

If you want to stream out dynamic content, chunk coding is the only
option.

Oleg 




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


Mime
View raw message