in client/src/main/java/org/apache/ahc/codec/HttpResponseDecoder.java [48:128]
protected boolean doDecode(IoSession ioSession, IoBuffer in, ProtocolDecoderOutput out)
throws Exception {
try {
HttpResponseMessage response = (HttpResponseMessage)ioSession.getAttribute(HttpIoHandler.CURRENT_RESPONSE);
if (response == null) {
response = new HttpResponseMessage();
ioSession.setAttribute(HttpIoHandler.CURRENT_RESPONSE, response);
}
//Test if we need the response...
if (response.getState() == HttpResponseMessage.STATE_START) {
if (!processStatus(response, in)) {
throw new NeedMoreDataException();
}
//Handle HTTP/1.1 100 Continue
if (response.getStatusCode() == 100) {
response.setState(HttpResponseMessage.STATE_STATUS_CONTINUE);
} else {
response.setState(HttpResponseMessage.STATE_STATUS_READ);
}
}
//If we are in a 100 Continue, read until we get the real header
if (response.getState() == HttpResponseMessage.STATE_STATUS_CONTINUE) {
//Continue reading until we get a blank line
while (true) {
String line = httpDecoder.decodeLine(in);
//Check if the entire response has been read
if (line == null) {
throw new NeedMoreDataException();
}
//Check if the entire response headers have been read
if (line.length() == 0) {
response.setState(HttpResponseMessage.STATE_STATUS_READ);
//The next line should be a header
if (!processStatus(response, in)) {
throw new NeedMoreDataException();
}
break;
}
}
}
//Are we reading headers?
if (response.getState() == HttpResponseMessage.STATE_STATUS_READ) {
if (!processHeaders(response, in)) {
throw new NeedMoreDataException();
}
}
//Are we reading content?
if (response.getState() == HttpResponseMessage.STATE_HEADERS_READ) {
if (!processContent(response, in)) {
throw new NeedMoreDataException();
}
}
//If we are chunked and we have read all the content, then read the footers if there are any
if (response.isChunked() && response.getState() == HttpResponseMessage.STATE_CONTENT_READ) {
if (!processFooters(response, in)) {
throw new NeedMoreDataException();
}
}
response.setState(HttpResponseMessage.STATE_FINISHED);
out.write(response);
ioSession.removeAttribute(HttpIoHandler.CURRENT_RESPONSE);
return true;
} catch (NeedMoreDataException e) {
return false;
}
}