| 1069 | } |
| 1070 | |
| 1071 | bool |
| 1072 | ContentTypeHandler::nextObjectHeader(TSMBuffer bufp, TSMLoc hdr_loc) |
| 1073 | { |
| 1074 | TSMLoc field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, TS_MIME_FIELD_CONTENT_TYPE, TS_MIME_LEN_CONTENT_TYPE); |
| 1075 | if (field_loc != TS_NULL_MLOC) { |
| 1076 | bool values_added = false; |
| 1077 | const char *value; |
| 1078 | int value_len; |
| 1079 | int n_values = TSMimeHdrFieldValuesCount(bufp, hdr_loc, field_loc); |
| 1080 | for (int i = 0; i < n_values; ++i) { |
| 1081 | value = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, i, &value_len); |
| 1082 | swoc::TextView tv{value, size_t(value_len)}; |
| 1083 | tv = tv.take_prefix_at(';').rtrim(" \t"_tv); |
| 1084 | if (_content_type_allowlist.empty()) { |
| 1085 | ; |
| 1086 | } else if (std::find_if(_content_type_allowlist.begin(), _content_type_allowlist.end(), [tv](swoc::TextView tv2) -> bool { |
| 1087 | return strcasecmp(tv, tv2) == 0; |
| 1088 | }) == _content_type_allowlist.end()) { |
| 1089 | return false; |
| 1090 | } else if (tv.empty()) { |
| 1091 | // allowlist is bad, contains an empty string. |
| 1092 | return false; |
| 1093 | } |
| 1094 | if (!_added_content_type) { |
| 1095 | if (!values_added) { |
| 1096 | _resp_header_fields.append("Content-Type: "); |
| 1097 | values_added = true; |
| 1098 | } else { |
| 1099 | _resp_header_fields.append(", "); |
| 1100 | } |
| 1101 | _resp_header_fields.append(value, value_len); |
| 1102 | } |
| 1103 | } |
| 1104 | TSHandleMLocRelease(bufp, hdr_loc, field_loc); |
| 1105 | if (values_added) { |
| 1106 | _resp_header_fields.append("\r\n"); |
| 1107 | |
| 1108 | // Assume that the Content-type field from the first header covers all the responses being combined. |
| 1109 | _added_content_type = true; |
| 1110 | } |
| 1111 | return true; |
| 1112 | } |
| 1113 | // No content type header field so doesn't pass allowlist if there is one. |
| 1114 | return _content_type_allowlist.empty(); |
| 1115 | } |
| 1116 | |
| 1117 | void |
| 1118 | ContentTypeHandler::loadAllowList(std::string const &file_spec) |
no test coverage detected