this.res = res;
String contentRangeHeader = res.getHeader("Content-Range");
int length = res.content.readableBytes();
if (!StringHelper.isEmptyString(contentRangeHeader))
{
ContentRangeHeaderValue v = new ContentRangeHeaderValue(
contentRangeHeader);
length = (int) v.getInstanceLength();
}
if (this.contentEnd == -1)
{
this.contentEnd = length - 1;
}
if (null != originRangeHader)
{
res.statusCode = 206;
res.setHeader("Content-Range", String.format(
"bytes %d-%d/%d", this.contentBegin,
this.contentEnd, length));
}
else
{
res.statusCode = 200;
res.removeHeader("Content-Range");
}
res.setHeader("Content-Length", ""
+ (this.contentEnd - this.contentBegin + 1));
int n = res.content.readableBytes();
this.expectedRangePos += n;
this.rangePos += n;
cb.onHttpResponse(res);
rangeState = STATE_WAIT_RANGE_GET_RES;
break;
}
case STATE_WAIT_RANGE_GET_RES:
{
if (res.statusCode != 206)
{
logger.error("Expected 206 response, but got "
+ res.statusCode);
if(res.getHeader("X-Range") != null)
{
fetchWorkerNum = 1;
final HTTPRequestEvent freq = cloneRequest(req);
freq.setHeader("Range", res.getHeader("X-Range"));
SharedObjectHelper.getGlobalTimer().schedule(new Runnable()
{
public void run()
{
cb.writeHttpReq(freq);
}
}, 1, TimeUnit.SECONDS);
return true;
}
return false;
}
rangeWorker.decrementAndGet();
String contentRangeHeader = res.getHeader("Content-Range");
ContentRangeHeaderValue v = new ContentRangeHeaderValue(
contentRangeHeader);
logger.info(String.format("Session[%d]Recv range chunk:%s",
this.sessionID, contentRangeHeader));
chunks.put((int) v.getFirstBytePos(), res.content);
while (chunks.containsKey(expectedRangePos))
{
Buffer chunk = chunks.remove(expectedRangePos);
expectedRangePos += chunk.readableBytes();
cb.onRangeChunk(chunk);