MCPcopy Create free account
hub / github.com/apache/trafficserver / CalcVariability

Method CalcVariability

src/iocore/cache/HttpTransactCache.cc:1200–1287  ·  view source on GitHub ↗

If the cached object contains a Vary header, then the object only matches if ALL of the headers named in Vary are present in the new request, and these match the headers in the stored request. We relax this rule to allow matches if neither the current nor original client headers contained a varying header. This is different from what is stated in the specs. */

Source from the content-addressed store, hash-verified

1198
1199*/
1200Variability_t
1201HttpTransactCache::CalcVariability(const HttpConfigAccessor *http_config_params, HTTPHdr *client_request,
1202 HTTPHdr *obj_client_request, HTTPHdr *obj_origin_server_response)
1203{
1204 ink_assert(http_config_params != nullptr);
1205 ink_assert(client_request != nullptr);
1206 ink_assert(obj_client_request != nullptr);
1207 ink_assert(obj_origin_server_response != nullptr);
1208
1209 Variability_t variability = VARIABILITY_NONE;
1210 if (obj_origin_server_response->presence(MIME_PRESENCE_VARY)) {
1211 StrList vary_list;
1212
1213 if (obj_origin_server_response->value_get_comma_list(MIME_FIELD_VARY, MIME_LEN_VARY, &vary_list) > 0) {
1214 if (dbg_ctl_http_match.on() && vary_list.head) {
1215 DbgPrint(dbg_ctl_http_match, "Vary list of %d elements", vary_list.count);
1216 vary_list.dump(stderr);
1217 }
1218
1219 // for each field that varies, see if current & original hdrs match //
1220 for (Str *field = vary_list.head; field != nullptr; field = field->next) {
1221 if (field->len == 0) {
1222 continue;
1223 }
1224
1225 /////////////////////////////////////////////////////////////
1226 // If the field name is unhandled, we should probably do a //
1227 // string comparison on the values of this extension field //
1228 // but currently we just treat it equivalent to a '*'. //
1229 /////////////////////////////////////////////////////////////
1230
1231 Dbg(dbg_ctl_http_match, "Vary: %s", field->str);
1232 if (((field->str[0] == '*') && (field->str[1] == NUL))) {
1233 Dbg(dbg_ctl_http_match, "Wildcard variability --- object not served from cache");
1234 variability = VARIABILITY_ALL;
1235 break;
1236 }
1237 ////////////////////////////////////////////////////////////////////////////////////////
1238 // Special case: if 'proxy.config.http.global_user_agent_header' set //
1239 // we should ignore Vary: User-Agent. //
1240 ////////////////////////////////////////////////////////////////////////////////////////
1241 if (http_config_params->get_global_user_agent_header() && !strcasecmp(const_cast<char *>(field->str), "User-Agent")) {
1242 continue;
1243 }
1244
1245 // Disable Vary mismatch checking for Accept-Encoding. This is only safe to
1246 // set if you are promising to fix any Accept-Encoding/Content-Encoding mismatches.
1247 if (http_config_params->get_ignore_accept_encoding_mismatch() &&
1248 !strcasecmp(const_cast<char *>(field->str), "Accept-Encoding")) {
1249 continue;
1250 }
1251
1252 ///////////////////////////////////////////////////////////////////
1253 // Take the current vary field and look up the headers in //
1254 // the current client, and the original client. The cached //
1255 // object varies unless BOTH the current client and the original //
1256 // client contain the header, and the header values are equal. //
1257 // We relax this to allow a match if NEITHER have the header. //

Callers

nothing calls this directly

Calls 9

strcasecmpFunction · 0.85
hdrtoken_string_to_wksFunction · 0.85
presenceMethod · 0.80
value_get_comma_listMethod · 0.80
field_findMethod · 0.80
onMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected