| 1062 | } |
| 1063 | |
| 1064 | static int |
| 1065 | modifyResponseHeader(TSCont contp, TSEvent event, void *edata) |
| 1066 | { |
| 1067 | int retval = 0; |
| 1068 | RespHdrModData *mod_data = static_cast<RespHdrModData *>(TSContDataGet(contp)); |
| 1069 | TSHttpTxn txnp = static_cast<TSHttpTxn>(edata); |
| 1070 | if (event != TS_EVENT_HTTP_SEND_RESPONSE_HDR) { |
| 1071 | TSError("[esi][%s] Unexpected event (%d)", __FUNCTION__, event); |
| 1072 | goto lReturn; |
| 1073 | } |
| 1074 | TSMBuffer bufp; |
| 1075 | TSMLoc hdr_loc; |
| 1076 | if (TSHttpTxnClientRespGet(txnp, &bufp, &hdr_loc) == TS_SUCCESS) { |
| 1077 | int n_mime_headers = TSMimeHdrFieldsCount(bufp, hdr_loc); |
| 1078 | TSMLoc field_loc; |
| 1079 | const char *name, *value; |
| 1080 | int name_len, value_len; |
| 1081 | for (int i = 0; i < n_mime_headers; ++i) { |
| 1082 | field_loc = TSMimeHdrFieldGet(bufp, hdr_loc, i); |
| 1083 | if (!field_loc) { |
| 1084 | Dbg(dbg_ctl_local, "[%s] Error while obtaining header field #%d", __FUNCTION__, i); |
| 1085 | continue; |
| 1086 | } |
| 1087 | name = TSMimeHdrFieldNameGet(bufp, hdr_loc, field_loc, &name_len); |
| 1088 | if (name) { |
| 1089 | bool destroy_header = false; |
| 1090 | |
| 1091 | if (Utils::areEqual(name, name_len, SERVER_INTERCEPT_HEADER, SERVER_INTERCEPT_HEADER_LEN)) { |
| 1092 | destroy_header = true; |
| 1093 | } else if (Utils::areEqual(name, name_len, TS_MIME_FIELD_AGE, TS_MIME_LEN_AGE)) { |
| 1094 | destroy_header = true; |
| 1095 | } else if (Utils::areEqual(name, name_len, MIME_FIELD_XESI, MIME_FIELD_XESI_LEN)) { |
| 1096 | destroy_header = true; |
| 1097 | } else if ((name_len > HEADER_MASK_PREFIX_SIZE) && (strncmp(name, HEADER_MASK_PREFIX, HEADER_MASK_PREFIX_SIZE) == 0)) { |
| 1098 | destroy_header = true; |
| 1099 | } else if (mod_data->option_info->private_response && |
| 1100 | (Utils::areEqual(name, name_len, TS_MIME_FIELD_CACHE_CONTROL, TS_MIME_LEN_CACHE_CONTROL) || |
| 1101 | Utils::areEqual(name, name_len, TS_MIME_FIELD_EXPIRES, TS_MIME_LEN_EXPIRES))) { |
| 1102 | destroy_header = true; |
| 1103 | } else if (Utils::areEqual(name, name_len, TS_MIME_FIELD_CONTENT_LENGTH, TS_MIME_LEN_CONTENT_LENGTH)) { |
| 1104 | if (mod_data->head_only) { |
| 1105 | destroy_header = true; |
| 1106 | Dbg(dbg_ctl_local, "[%s] remove Content-Length", __FUNCTION__); |
| 1107 | } |
| 1108 | } else { |
| 1109 | int n_field_values = TSMimeHdrFieldValuesCount(bufp, hdr_loc, field_loc); |
| 1110 | for (int j = 0; j < n_field_values; ++j) { |
| 1111 | value = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, j, &value_len); |
| 1112 | if (nullptr == value || !value_len) { |
| 1113 | Dbg(dbg_ctl_local, "[%s] Error while getting value #%d of header [%.*s]", __FUNCTION__, j, name_len, name); |
| 1114 | } else { |
| 1115 | if (!mod_data->option_info->packed_node_support || mod_data->cache_txn) { |
| 1116 | bool response_cacheable, is_cache_header; |
| 1117 | is_cache_header = checkForCacheHeader(name, name_len, value, value_len, response_cacheable); |
| 1118 | if (is_cache_header && response_cacheable) { |
| 1119 | destroy_header = true; |
| 1120 | } |
| 1121 | } |
nothing calls this directly
no test coverage detected