IoBuffer.allocate(oldBuffer.remaining() + msg.remaining()).put(oldBuffer).put(msg).flip();
// now let's decode like it was a new message
case NEW:
LOG.debug("decoding NEW");
final DefaultHttpResponse rp = parseHttpReponseHead(msg.buf());
if (rp == null) {
// we copy the incoming BB because it's going to be recycled by the inner IoProcessor for next reads
final ByteBuffer partial = ByteBuffer.allocate(msg.remaining());
partial.put(msg.buf());
partial.flip();
// no request decoded, we accumulate
session.setAttribute(PARTIAL_HEAD_ATT, partial);
session.setAttribute(DECODER_STATE_ATT, DecoderState.HEAD);
} else {
out.write(rp);
// is it a response with some body content ?
LOG.debug("response with content");
session.setAttribute(DECODER_STATE_ATT, DecoderState.BODY);
final String contentLen = rp.getHeader("content-length");
if (contentLen != null) {
LOG.debug("found content len : {}", contentLen);
session.setAttribute(BODY_REMAINING_BYTES, Integer.valueOf(contentLen));
} else if ("chunked".equalsIgnoreCase(rp.getHeader("transfer-encoding"))) {
LOG.debug("no content len but chunked");
session.setAttribute(BODY_CHUNKED, Boolean.valueOf("true"));
} else if ("close".equalsIgnoreCase(rp.getHeader("connection"))) {
session.close(true);
} else {
throw new HttpException(HttpStatus.CLIENT_ERROR_LENGTH_REQUIRED, "no content length !");
}
}