On Mon, Aug 03, 2009 at 04:03:34PM -0700, Ken Krugler wrote: > In the ClientAbortMethod.java example, there's a call made to > entity.getContentLength() > > Previously I was getting the first content-length header and parsing > that to extract the length, but I switched to using this call. > > However my integration tests then all started failing, as this call > would return -1 in all the cases I walked through in the debugger. > > So two questions: > > 1. When would it make sense to use this call? >
To get a hint what content length might be. For instance, if the content length is positive and is relatively small, one may be better off reading the content body to the end; if the content length is unknown one may want to simply abort the request at the expense of not reusing the underlying connection. > 2. Is the sample code wrong, or is there something I'm doing in my code > that could cause the -1 result in all cases? > I do not think there is anything wrong with the example. If content is chunk coded its length is simply cannot be determined until it is fully consumed. It this case HttpEntity#getContentLength() return -1. Hope this helps Oleg > Thanks, > > -- Ken > > -------------------------- > Ken Krugler > TransPac Software, Inc. > <http://www.transpac.com> > +1 530-210-6378 > > > --------------------------------------------------------------------- > 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]
