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

Method update

plugins/esi/combo_handler.cc:252–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

250}
251
252void
253CacheControlHeader::update(TSMBuffer bufp, TSMLoc hdr_loc)
254{
255 bool found_immutable = false;
256 bool found_private = false;
257
258 // Load each value from the Cache-Control header into the vector values
259 TSMLoc field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, TS_MIME_FIELD_CACHE_CONTROL, TS_MIME_LEN_CACHE_CONTROL);
260 if (field_loc != TS_NULL_MLOC) {
261 int n_values = TSMimeHdrFieldValuesCount(bufp, hdr_loc, field_loc);
262 if ((n_values != TS_ERROR) && (n_values > 0)) {
263 for (int i = 0; i < n_values; i++) {
264 // Grab this current header value
265 int _val_len = 0;
266 const char *val = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, i, &_val_len);
267
268 // Update max-age if necessary
269 if (strncasecmp(val, TS_HTTP_VALUE_MAX_AGE, TS_HTTP_LEN_MAX_AGE) == 0) {
270 unsigned int max_age = 0;
271 char *ptr = const_cast<char *>(val);
272 ptr += TS_HTTP_LEN_MAX_AGE;
273 while ((*ptr == ' ') || (*ptr == '\t')) {
274 ptr++;
275 }
276 if (*ptr == '=') {
277 ptr++;
278 max_age = atoi(ptr);
279 }
280 if (max_age > 0 && max_age < _max_age) {
281 _max_age = max_age;
282 }
283 // If we find even a single occurrence of private, the whole response must be private
284 } else if (strncasecmp(val, TS_HTTP_VALUE_PRIVATE, TS_HTTP_LEN_PRIVATE) == 0) {
285 found_private = true;
286 // Every requested document must have immutable for the final response to be immutable
287 } else if (strncasecmp(val, HTTP_IMMUTABLE, strlen(HTTP_IMMUTABLE)) == 0) {
288 found_immutable = true;
289 }
290 }
291 }
292 TSHandleMLocRelease(bufp, hdr_loc, field_loc);
293 }
294
295 if (!found_immutable) {
296 LOG_DEBUG("Did not see an immutable cache control. The response will be not be immutable");
297 _immutable = false;
298 }
299
300 if (found_private) {
301 LOG_DEBUG("Saw a private cache control. The response will be private");
302 _publicity = Publicity::PRIVATE;
303 }
304}
305
306string
307CacheControlHeader::generate() const

Callers 2

prepareResponseFunction · 0.45
invokeMethod · 0.45

Calls 4

TSMimeHdrFieldFindFunction · 0.85
TSHandleMLocReleaseFunction · 0.85

Tested by

no test coverage detected