String nameText = name.getText();
//Transfer-Encoding
if (HeaderNames.TRANSFER_ENCODING.equals(nameText)) {
if (HeaderValues.CHUNKED.equals(value.getText())) {
//chunked
IBooleanValue chunked = factory.createBoolean();
chunked.setBoolean(true);
fieldStack.setTopField(StackFields.CHUNCKED, chunked);
//hasBody
IBooleanValue hasBody = factory.createBoolean();
hasBody.setBoolean(true);
fieldStack.setTopField(StackFields.HAS_BODY, hasBody);
}
//Content-Length
} else if (HeaderNames.CONTENT_LENGTH.equals(nameText)) {
try {
int contentLength = Integer.parseInt(value.getText());
if (contentLength > 0) {
//hasBody
IBooleanValue hasBody = factory.createBoolean();
hasBody.setBoolean(true);
fieldStack.setTopField(StackFields.HAS_BODY, hasBody);
//contentLength
IIntegerValue lenValue = factory.createInteger();
lenValue.setInteger(contentLength);
fieldStack.setTopField(StackFields.CONTENT_LENGTH, lenValue);
}
} catch (NumberFormatException e) {
//忽略错误长度
}
//Trailer
} else if (HeaderNames.TRAILER.equals(nameText)) {
String[] names = SPACE_DELIMITER.split(value.getText());
Set<String> nameSet = new TreeSet<String>();
for (int i = 0; i < names.length; i++) {
String trailerName = names[i].trim();
if (trailerName.length() > 0) {
nameSet.add(trailerName);
}
}
if (nameSet.size() > 0) {
//hasTrailers
IBooleanValue hasTrailers = factory.createBoolean();
hasTrailers.setBoolean(true);
fieldStack.setTopField(StackFields.HAS_TRAILERS, hasTrailers);
//trailerNames
fieldStack.setTopField(StackFields.TRAILER_NAMES, nameSet);
}
}