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