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

Function InjectCacheHeader

plugins/xdebug/xdebug.cc:257–291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255}
256
257static void
258InjectCacheHeader(TSHttpTxn txn, TSMBuffer buffer, TSMLoc hdr)
259{
260 TSMLoc dst = TS_NULL_MLOC;
261 int status;
262
263 static const char *names[] = {
264 "miss", // TS_CACHE_LOOKUP_MISS,
265 "hit-stale", // TS_CACHE_LOOKUP_HIT_STALE,
266 "hit-fresh", // TS_CACHE_LOOKUP_HIT_FRESH,
267 "skipped" // TS_CACHE_LOOKUP_SKIPPED
268 };
269
270 Dbg(dbg_ctl, "attempting to inject X-Cache header");
271
272 // Create a new response header field.
273 dst = FindOrMakeHdrField(buffer, hdr, "X-Cache", lengthof("X-Cache"));
274 if (dst == TS_NULL_MLOC) {
275 goto done;
276 }
277
278 if (TSHttpTxnCacheLookupStatusGet(txn, &status) == TS_ERROR) {
279 // If the cache lookup hasn't happened yes, TSHttpTxnCacheLookupStatusGet will fail.
280 TSReleaseAssert(TSMimeHdrFieldValueStringInsert(buffer, hdr, dst, -1 /* idx */, "none", 4) == TS_SUCCESS);
281 } else {
282 const char *msg = (status < 0 || status >= static_cast<int>(countof(names))) ? "unknown" : names[status];
283
284 TSReleaseAssert(TSMimeHdrFieldValueStringInsert(buffer, hdr, dst, -1 /* idx */, msg, -1) == TS_SUCCESS);
285 }
286
287done:
288 if (dst != TS_NULL_MLOC) {
289 TSHandleMLocRelease(buffer, hdr, dst);
290 }
291}
292
293struct milestone {
294 TSMilestonesType mstype;

Callers 1

XInjectResponseHeadersFunction · 0.85

Calls 6

FindOrMakeHdrFieldFunction · 0.85
TSHandleMLocReleaseFunction · 0.85
lengthofFunction · 0.70
countofFunction · 0.50

Tested by

no test coverage detected