Ah, getting there - almost! I was making the mistake of trying to cast the InputStream of a BufferedHttpEntity. If I instead try response.getEntity().getContent() (i.e. work with the BasicManagedEntity that it gives me) I get an EofSensorInputStream which, I can see in debug, wraps a ChunkedInputStream. However, the ChunkedInputStream is still invisible! Can I somehow get access to that ChunkedInputStream?
Agreed on instead adding any trailing information to the tail of the response body. However, I'm meant to be testing a client's full adherence to HTTP/1.1, so I have to check the trailers. Thanks for your help, Ben ---------------------------------------- > Date: Wed, 3 Feb 2010 23:38:36 +0100 > From: [email protected] > To: [email protected] > Subject: Re: HTTP Trailers in HttpClient 4.0.1 > > Ben Cox wrote: >> Oleg, >> >> Thanks for your response. That's interesting - as you say, using trailers is >> somewhat of an edge case, though there's something to be said for using them >> as part of mashup-type applications in which data may be being sent over an >> extended period, so some state may be unknown at the beginning of >> transmission. > > That begs a question: why not just send it at the end of the response body > >> >> I'd spotted the ChunkedInputStream before, but was unable to use it. Which >> InputStream are you referring to? I tried casting entity.getContent(), but >> that's a ByteArrayInputStream, and I can't find an InputStream for the >> response itself. >> > > I double-checked and am pretty sure HttpEntity#getContent() of the > response entity should return ChunkedInputStream if the response body is > chunk coded. > > Oleg > >> Thanks, >> Ben >> >> >> ---------------------------------------- >>> Subject: Re: HTTP Trailers in HttpClient 4.0.1 >>> From: [email protected] >>> To: [email protected] >>> Date: Wed, 3 Feb 2010 11:41:25 +0100 >>> >>> On Tue, 2010-02-02 at 21:07 +0000, Ben Cox wrote: >>>> Hi all, >>>> >>>> I'm testing out using chunked encoding with trailing headers at the >>>> moment, but seem to be having some problems getting the HttpClient to find >>>> the trailers. My code looks like this: >>>> >>>> /***************************************************************/ >>>> >>>> HttpClient httpClient = new DefaultHttpClient(); >>>> HttpGet httpGet = new HttpGet(url); >>>> >>>> // Tell the server that we can deal with trailers >>>> httpGet.addHeader("TE", "trailers"); >>>> >>>> // Get the response >>>> HttpResponse response = httpClient.execute(httpGet); >>>> >>>> // Print out all the headers we have >>>> for (Header aHeader : response.getAllHeaders()) { >>>> System.out.println(aHeader.getName() + ": " + aHeader.getValue()); >>>> } >>>> >>>> /***************************************************************/ >>>> >>>> The resultant document is transferred in around 100 chunks. >>>> >>>> I get all the other trailers I might expect to be printed, including the >>>> "Trailer: Mytrailer" one that describes what trailers I should I expect. >>>> However, I don't get "Mytrailer" at all, though I can see it on the wire >>>> if I use Wireshark. >>>> >>>> I noticed in the 3.x documentation there seems to be a lot more info about >>>> chunked encoding and trailers/footers. However, there's not so much in the >>>> 4.0.1 documentation. Is this not supported any more, or just more >>>> integrated into normal headers and I've got something wrong? >>>> >>>> Any help is much appreciated. >>>> >>>> Thanks, >>>> Ben >>>> >>> Hi Ben >>> >>> I personally have never seen trailers/footers used in any of the >>> real-world application. This seems to be no convincing use case for >>> them. This is the reason trailing headers in Httpclient 4.0 can only be >>> accessed by casting the response InputStream to ChunkInputStream and >>> calling ChunkInputStream#getFooters once the end of the stream has been >>> reached. >>> >>> Hope this helps >>> >>> Oleg >>> >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [email protected] >>> For additional commands, e-mail: [email protected] >>> >> >> _________________________________________________________________ >> Send us your Hotmail stories and be featured in our newsletter >> http://clk.atdmt.com/UKM/go/195013117/direct/01/ >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > _________________________________________________________________ Do you have a story that started on Hotmail? Tell us now http://clk.atdmt.com/UKM/go/195013117/direct/01/ --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
