if (request.getHeaderParsingState().contentLengthsDiffer) {
request.getProcessingState().error = true;
return;
}
final MimeHeaders headers = request.getHeaders();
DataChunk hostDC = null;
// Check for a full URI (including protocol://host:port/)
final DataChunk uriBC = request.getRequestURIRef().getRequestURIBC();
if (uriBC.startsWithIgnoreCase("http", 0)) {
int pos = uriBC.indexOf("://", 4);
int uriBCStart = uriBC.getStart();
int slashPos;
if (pos != -1) {
// final Buffer uriB = uriBC.getBuffer();
slashPos = uriBC.indexOf('/', pos + 3);
if (slashPos == -1) {
slashPos = uriBC.getLength();
// Set URI as "/"
uriBC.setStart(uriBCStart + pos + 1);
uriBC.setEnd(uriBCStart + pos + 2);
} else {
uriBC.setStart(uriBCStart + slashPos);
uriBC.setEnd(uriBC.getEnd());
}
hostDC = headers.setValue(Header.Host);
hostDC.set(uriBC, uriBCStart + pos + 3, uriBCStart + slashPos);
}
}
// --------------------------
if (hostDC == null) {
hostDC = headers.getValue(Header.Host);
}
final boolean isHttp11 = protocol == Protocol.HTTP_1_1;
// Check host header
if (isHttp11 && (hostDC == null || hostDC.isNull())) {
state.error = true;
return;
}
request.unparsedHostC = hostDC;
// If it's upgraded HTTP - don't check semantics
if (isUpgraded) {
return;
}
final Method method = request.getMethod();
final PayloadExpectation payloadExpectation = method.getPayloadExpectation();
if (payloadExpectation != PayloadExpectation.NOT_ALLOWED) {
final boolean hasPayload =
request.getContentLength() > 0 || request.isChunked();
if (hasPayload && payloadExpectation == PayloadExpectation.UNDEFINED &&
!allowPayloadForUndefinedHttpMethods) {
// if payload is not allowed for the "undefined" methods
state.error = true;
// Send 400; Bad Request
HttpStatus.BAD_REQUEST_400.setValues(response);
return;
}
request.setExpectContent(hasPayload);
} else {
request.setExpectContent(method == Method.CONNECT);
}
// ------ Set keep-alive flag
if (method == Method.CONNECT) {
state.keepAlive = false;
} else {
final DataChunk connectionValueDC = headers.getValue(Header.Connection);
final boolean isConnectionClose = (connectionValueDC != null &&
connectionValueDC.equalsIgnoreCaseLowerCase(CLOSE_BYTES));
if (!isConnectionClose) {
state.keepAlive = allowKeepAlive && (isHttp11 ||