in common/src/main/java/org/apache/asyncweb/common/codec/HttpRequestDecodingStateMachine.java [108:195]
protected DecodingState finishDecode(List<Object> childProducts,
ProtocolDecoderOutput out) throws Exception {
Map<String, List<String>> headers =
(Map<String, List<String>>) childProducts.get(0);
// Set cookies.
List<String> cookies = headers.get(
HttpHeaderConstants.KEY_COOKIE);
if (cookies != null && !cookies.isEmpty()) {
if (cookies.size() > 1) {
if (LOG.isWarnEnabled()) {
LOG.warn("Ignoring extra cookie headers: "
+ cookies.subList(1, cookies.size()));
}
}
request.setCookies(cookies.get(0));
}
// Set headers.
request.setHeaders(headers);
if (LOG.isDebugEnabled()) {
LOG.debug("Decoded header: " + request.getHeaders());
}
// Select appropriate body decoding state.
boolean isChunked = false;
if (request.getProtocolVersion() == HttpVersion.HTTP_1_1) {
LOG.debug("Request is HTTP 1/1. Checking for transfer coding");
isChunked = isChunked(request);
} else {
LOG.debug("Request is not HTTP 1/1. Using content length");
}
DecodingState nextState;
if (isChunked) {
LOG.debug("Using chunked decoder for request");
nextState = new ChunkedBodyDecodingState() {
@Override
protected DecodingState finishDecode(
List<Object> childProducts,
ProtocolDecoderOutput out) throws Exception {
if (childProducts.size() != 1) {
int chunkSize = 0;
for (Object product : childProducts) {
IoBuffer chunk = (IoBuffer) product;
chunkSize += chunk.remaining();
}
IoBuffer body = IoBuffer.allocate(chunkSize);
for (Object product : childProducts) {
IoBuffer chunk = (IoBuffer) product;
body.put(chunk);
}
body.flip();
request.setContent(body);
} else {
request.setContent((IoBuffer) childProducts.get(0));
}
out.write(request);
return null;
}
};
} else {
int length = getContentLength(request);
if (length > 0) {
if (LOG.isDebugEnabled()) {
LOG
.debug("Using fixed length decoder for request with length "
+ length);
}
nextState = new FixedLengthDecodingState(length) {
@Override
protected DecodingState finishDecode(IoBuffer readData,
ProtocolDecoderOutput out) throws Exception {
request.setContent(readData);
out.write(request);
return null;
}
};
} else {
LOG.debug("No entity body for this request");
out.write(request);
nextState = null;
}
}
return nextState;
}