@Override
protected int state1(Channel ctx) {
ctx.log("receiving response");
final BufRanges head = ctx.helper().ranges1.reset();
final BufRanges body = ctx.helper().ranges2.reset();
Buf in = ctx.input();
in.scanLnLn(head);
Map<String, String> headers = head.toMap(in.bytes(), 1, head.count - 1, "\\s*\\:\\s*");
Map<String, String> headersLow = Msc.lowercase(headers);
if ("chunked".equals(headersLow.get("transfer-encoding"))) {
ctx.log("got chunked encoding");
parseChunkedBody(in, body);
callback.onResult(in, head, body);
} else if (headersLow.containsKey("content-length")) {
ctx.log("got content length");
int clength = Integer.parseInt(headersLow.get("content-length"));
parseBodyByContentLength(in, body, clength);
callback.onResult(in, head, body);
} else {
ctx.log("read until closed");
readBodyUntilClosed(ctx, body);
callback.onResult(in, head, body);
}
ctx.log("done");
ctx.close();
return STOP;
}