}
// input connection closed ?
closeStreamOnEnd("Closed input");
return;
}
BBucket rawBuf = rawReceiveBuffers.peekFirst();
if (rawBuf == null) {
return; // need more data
}
if (!bodys.isContentDelimited()) {
while (true) {
BBucket first = rawReceiveBuffers.popFirst();
if (first == null) {
break; // will go back to check if done.
} else {
received(body, first);
}
}
} else {
if (bodys.contentLength >= 0 && bodys.remaining == 0) {
receiveDone(http, body, false);
return;
}
if (bodys.chunked && bodys.remaining == 0) {
int rc = NEED_MORE;
// TODO: simplify, use readLine()
while (rc == NEED_MORE) {
rc = rchunk.parseChunkHeader(rawReceiveBuffers);
if (rc == ERROR) {
http.abort("Chunk error");
receiveDone(http, body, true);
return;
} else if (rc == NEED_MORE) {
return;
}
}
if (rc == 0) { // last chunk
receiveDone(http, body, false);
return;
} else {
bodys.remaining = rc;
}
}
rawBuf = (BBucket) rawReceiveBuffers.peekFirst();
if (rawBuf == null) {
return; // need more data
}
if (bodys.remaining < rawBuf.remaining()) {
// To buffer has more data than we need.
int lenToConsume = (int) bodys.remaining;
BBucket sb = rawReceiveBuffers.popLen(lenToConsume);
received(body, sb);
//log.info("Queue received buffer " + this + " " + lenToConsume);
bodys.remaining = 0;
} else {
BBucket first = rawReceiveBuffers.popFirst();
bodys.remaining -= first.remaining();
received(body, first);
//log.info("Queue full received buffer " + this + " RAW: " + rawReceiveBuffers);
}
if (bodys.contentLength >= 0 && bodys.remaining == 0) {
// Content-Length, all done