| 255 | } |
| 256 | |
| 257 | static void |
| 258 | InjectCacheHeader(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 | |
| 287 | done: |
| 288 | if (dst != TS_NULL_MLOC) { |
| 289 | TSHandleMLocRelease(buffer, hdr, dst); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | struct milestone { |
| 294 | TSMilestonesType mstype; |
no test coverage detected