| 420 | } |
| 421 | |
| 422 | static void |
| 423 | InjectEffectiveURLHeader(TSHttpTxn txn, TSMBuffer buffer, TSMLoc hdr) |
| 424 | { |
| 425 | struct { |
| 426 | char *ptr; |
| 427 | int len; |
| 428 | } strval = {nullptr, 0}; |
| 429 | |
| 430 | Dbg(dbg_ctl, "attempting to inject X-Effective-URL header"); |
| 431 | |
| 432 | strval.ptr = TSHttpTxnEffectiveUrlStringGet(txn, &strval.len); |
| 433 | |
| 434 | if (strval.ptr != nullptr && strval.len > 0) { |
| 435 | TSMLoc dst = FindOrMakeHdrField(buffer, hdr, "X-Effective-URL", lengthof("X-Effective-URL")); |
| 436 | if (dst != TS_NULL_MLOC) { |
| 437 | char buf[16 * 1024]; |
| 438 | int len = snprintf(buf, sizeof(buf), "\"%s\"", strval.ptr); |
| 439 | if (len == strval.len + 2 && len <= static_cast<int>(sizeof(buf)) - 1) { // Only copy back if len expected and within buffer. |
| 440 | TSReleaseAssert(TSMimeHdrFieldValueStringInsert(buffer, hdr, dst, -1 /* idx */, buf, len) == TS_SUCCESS); |
| 441 | } |
| 442 | TSHandleMLocRelease(buffer, hdr, dst); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | TSfree(strval.ptr); |
| 447 | } |
| 448 | |
| 449 | static void |
| 450 | InjectOriginalContentTypeHeader(TSMBuffer buffer, TSMLoc hdr) |
no test coverage detected