in client/src/main/java/org/apache/ahc/codec/HttpResponseDecoder.java [209:257]
private boolean processContent(HttpResponseMessage response, IoBuffer in) throws Exception {
if (response.isChunked()) {
while (true) {
//Check what kind of record we are reading (content or size)
if (response.getExpectedToRead() == HttpResponseMessage.EXPECTED_NOT_READ) {
//We haven't read the size, so we are expecting a size
String line = httpDecoder.decodeLine(in);
//Check if the entire line has been read
if (line == null) {
return false;
}
response.setExpectedToRead(httpDecoder.decodeSize(line));
//Are we done reading the chunked content? (A zero means we are done)
if (response.getExpectedToRead() == 0) {
break;
}
}
//Now read the content chunk
//Be sure all of the data is there for us to retrieve + the CRLF...
if (response.getExpectedToRead() + 2 > in.remaining()) {
//Need more data
return false;
}
//Read the content
httpDecoder.decodeChunkedContent(in, response);
//Flag that it's time to read a size record
response.setExpectedToRead(HttpResponseMessage.EXPECTED_NOT_READ);
}
} else if (response.getContentLength() > 0) {
//Do we have enough data?
if ((response.getContentLength()) > in.remaining()) {
return false;
}
httpDecoder.decodeContent(in, response);
}
response.setState(HttpResponseMessage.STATE_CONTENT_READ);
return true;
}