| 485 | } |
| 486 | |
| 487 | static void |
| 488 | InjectParentSelectionKeyHeader(TSHttpTxn txn, TSMBuffer buffer, TSMLoc hdr) |
| 489 | { |
| 490 | TSMLoc url = TS_NULL_MLOC; |
| 491 | TSMLoc dst = TS_NULL_MLOC; |
| 492 | |
| 493 | struct { |
| 494 | char *ptr; |
| 495 | int len; |
| 496 | } strval = {nullptr, 0}; |
| 497 | |
| 498 | Dbg(dbg_ctl, "attempting to inject X-ParentSelection-Key header"); |
| 499 | |
| 500 | if (TSUrlCreate(buffer, &url) != TS_SUCCESS) { |
| 501 | goto done; |
| 502 | } |
| 503 | |
| 504 | if (TSHttpTxnParentSelectionUrlGet(txn, buffer, url) != TS_SUCCESS) { |
| 505 | goto done; |
| 506 | } |
| 507 | |
| 508 | strval.ptr = TSUrlStringGet(buffer, url, &strval.len); |
| 509 | if (strval.ptr == nullptr || strval.len == 0) { |
| 510 | goto done; |
| 511 | } |
| 512 | |
| 513 | // Create a new response header field. |
| 514 | dst = FindOrMakeHdrField(buffer, hdr, "X-ParentSelection-Key", lengthof("X-ParentSelection-Key")); |
| 515 | if (dst == TS_NULL_MLOC) { |
| 516 | goto done; |
| 517 | } |
| 518 | |
| 519 | // Now copy the parent selection lookup URL into the response header. |
| 520 | TSReleaseAssert(TSMimeHdrFieldValueStringInsert(buffer, hdr, dst, -1 /* idx */, strval.ptr, strval.len) == TS_SUCCESS); |
| 521 | |
| 522 | done: |
| 523 | if (dst != TS_NULL_MLOC) { |
| 524 | TSHandleMLocRelease(buffer, hdr, dst); |
| 525 | } |
| 526 | |
| 527 | if (url != TS_NULL_MLOC) { |
| 528 | TSHandleMLocRelease(buffer, TS_NULL_MLOC, url); |
| 529 | } |
| 530 | |
| 531 | TSfree(strval.ptr); |
| 532 | } |
| 533 | |
| 534 | static int |
| 535 | XInjectResponseHeaders(TSCont /* contp */, TSEvent event, void *edata) |
no test coverage detected