switch (bodyType) {
case BODY_TYPE_EMTPY:
HttpResponse response = new HttpResponse(responseHeader);
IMessageHandler messageHandler = messageHeaderHandler.onMessageHeaderReceived(response);
messageHandler.onHeaderProcessed();
httpConnection.onMessageCompleteReceived(responseHeader);
setMessageHandler(messageHandler);
reset();
// next response? (-> pipelining)
if (rawData != null) {
return onData(httpConnection, rawData);
}
break;
case BODY_TYPE_FULL_MESSAGE:
AbstractNetworkBodyDataSource dataSource = new FullMessageBodyDataSource(responseHeader, responseHeader.getContentLength(), httpConnection);
setBodyDataSource(dataSource);
response = new HttpResponse(responseHeader, dataSource);
messageHandler = messageHeaderHandler.onMessageHeaderReceived(response);
try {
setMessageHandler(messageHandler);
response.getNonBlockingBody().setBodyDataReceiveTimeoutMillis(httpConnection.getBodyDataReceiveTimeoutMillis());
rawData = parserBody(httpConnection, rawData);
} finally {
messageHandler.onHeaderProcessed();
}
break;
case BODY_TYPE_WEBSOCKET:
dataSource = new FullMessageBodyDataSource(responseHeader, 16, httpConnection);
setBodyDataSource(dataSource);
response = new HttpResponse(responseHeader, dataSource);
response.removeHeader("Content-Length");
messageHandler = messageHeaderHandler.onMessageHeaderReceived(response);
try {
setMessageHandler(messageHandler);
response.getNonBlockingBody().setBodyDataReceiveTimeoutMillis(httpConnection.getBodyDataReceiveTimeoutMillis());
rawData = parserBody(httpConnection, rawData);
} finally {
messageHandler.onHeaderProcessed();
}
break;
case BODY_TYPE_SIMPLE:
dataSource = new SimpleMessageBodyDataSource(responseHeader, httpConnection);
setBodyDataSource(dataSource);
response = new HttpResponse(responseHeader, dataSource);
messageHandler = messageHeaderHandler.onMessageHeaderReceived(response);
try {
setMessageHandler(messageHandler);
response.getNonBlockingBody().setBodyDataReceiveTimeoutMillis(httpConnection.getBodyDataReceiveTimeoutMillis());
rawData = parserBody(httpConnection, rawData);
} finally {
messageHandler.onHeaderProcessed();
}
break;
case BODY_TYPE_MULTIPART_BYTERANGE:
dataSource = new MultipartByteRangeMessageBodyDataSource(httpConnection, responseHeader);
setBodyDataSource(dataSource);
response = new HttpResponse(responseHeader, dataSource);
messageHandler = messageHeaderHandler.onMessageHeaderReceived(response);
try {
setMessageHandler(messageHandler);
response.getNonBlockingBody().setBodyDataReceiveTimeoutMillis(httpConnection.getBodyDataReceiveTimeoutMillis());
rawData = parserBody(httpConnection, rawData);
} finally {
messageHandler.onHeaderProcessed();
}
break;
default: // BODY_TYPE_CHUNKED
dataSource = new FullMessageChunkedBodyDataSource(httpConnection, responseHeader);
setBodyDataSource(dataSource);
response = new HttpResponse(responseHeader, dataSource);
messageHandler = messageHeaderHandler.onMessageHeaderReceived(response);
try {
setMessageHandler(messageHandler);
response.getNonBlockingBody().setBodyDataReceiveTimeoutMillis(httpConnection.getBodyDataReceiveTimeoutMillis());
rawData = parserBody(httpConnection, rawData);
} finally {
messageHandler.onHeaderProcessed();
}
break;
}