updateContentLength(value);
}
}
private void updateContentLength(PValue value) {
IContainerValue msgValue = (IContainerValue)value;
//取得Content-Length首部字段
@SuppressWarnings("unchecked")
IListValue<IRecordSetValue> headers = (IListValue<IRecordSetValue>)
msgValue.getField(HTTP_MESSAGE__HEADERS);
IValue contentLengthValue = null;
if (headers != null) {
for (int i = 0; i < headers.getLength(); i++) {
IRecordSetValue header = headers.getItem(i);
if (header == null) {
continue;
}
IValue name = header.getField(HTTP_HEADER__NAME);
if (name == null) {
continue;
}
if (HeaderNames.CONTENT_LENGTH.equals(name.getText())) {
contentLengthValue = header.getField(HTTP_HEADER__VALUE);
}
}
}
//根据httpBody/data来更新
if (contentLengthValue != null) {
IContainerValue httpBody = (IContainerValue)msgValue.getField(
HTTP_MESSAGE__HTTP_BODY);
if (httpBody != null && !httpBody.notPresent()) {
IOctetstringValue data = (IOctetstringValue)httpBody.getField(
HTTP_BODY__DATA);
if (data != null) {
String text = Integer.toString(data.getLength());
contentLengthValue.setText(text);
}