Header contentLengthHeader = message.getFirstHeader(HTTP.CONTENT_LEN);
if (transferEncodingHeader != null) {
String s = transferEncodingHeader.getValue();
if (HTTP.CHUNK_CODING.equalsIgnoreCase(s)) {
if (message.getProtocolVersion().lessEquals(HttpVersion.HTTP_1_0)) {
throw new ProtocolException(
"Chunked transfer encoding not allowed for " +
message.getProtocolVersion());
}
return CHUNKED;
} else if (HTTP.IDENTITY_CODING.equalsIgnoreCase(s)) {
return IDENTITY;
} else {
throw new ProtocolException(
"Unsupported transfer encoding: " + s);
}
} else if (contentLengthHeader != null) {
String s = contentLengthHeader.getValue();
try {
long len = Long.parseLong(s);
if (len < 0) {
throw new ProtocolException("Negative content length: " + s);
}
return len;
} catch (NumberFormatException e) {
throw new ProtocolException("Invalid content length: " + s);
}
} else {
return IDENTITY;
}
}