On Thu, 2012-06-07 at 10:00 -0700, John Sheehy wrote: > Hi all, > > I'm using Http client 4.1.3 on android (I replaced the built-in version > with the version from http://hc.apache.org/httpcomponents-client-ga/ using > a different namespace). I'm not quite sure how to detect an aborted GET > request. The server response is streamed, and chunked etc., and my code to > read it (in an HttpResponseHandler, with response status 200) looks like so: > > HttpEntity entity = response.getEntity(); > > if (entity != null) { > InputStream inputStream = null; > try { > int n = 0; > inputStream = entity.getContent(); > while((n = inputStream.read(chunkBuf)) != -1) { > // do something with the chunkBuf... > }; > } catch (Exception e) { > // If the connection is aborted, should a Chunk or IO exception > be thrown? > } finally { > if(inputStream != null) { > inputStream.close(); > } > } > > When I abort the connection on the server (mid-stream so the chunk length > would not match the content), the response ends without throwing an > exception. Using curl to do the GET, I get something along the lines of: > > curl: (18) transfer closed with outstanding read data remaining > > Is there some special type I have to use to wrap the input stream (I note > in 3.x that there's a ChunkedInputStream, but can't figure out how to use > it in 4.1.x), or something I should set on the request? I note the > inputStream is of type EOFSensorInputStream.. I'm not going through any > proxies or anything like that. > > I would really appreciate any insight into how to detect this condition! > > Thanks, > John Sheehy
John HttpClient should throw TruncatedChunkException in case it encounters an incomplete content chunk. It will, however, silently ignore missing closing chunk. Please re-ran the test with wire logging activates to see whether or not the last content chunk gets truncated. Oleg --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
