Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/admin-guide/plugins/xdebug.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,9 @@ X-Transaction-ID
X-Remap
If the URL was remapped for a request, this header gives the *to* and *from* field from the line in remap.config that caused
the URL to be remapped.

X-ParentSelection-Key
The ``X-ParentSelection-Key`` header contains the URL that is used to
determine parent selection for an object in the Traffic Server. This
header is particularly useful if a custom parent selection key is
being used.
55 changes: 55 additions & 0 deletions plugins/xdebug/xdebug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ enum {
XHEADER_X_DUMP_HEADERS = 1u << 7,
XHEADER_X_REMAP = 1u << 8,
XHEADER_X_PROBE_HEADERS = 1u << 9,
XHEADER_X_PSELECT_KEY = 1u << 10,
};

static int XArgIndex = 0;
Expand Down Expand Up @@ -325,6 +326,53 @@ InjectTxnUuidHeader(TSHttpTxn txn, TSMBuffer buffer, TSMLoc hdr)
}
}

static void
InjectParentSelectionKeyHeader(TSHttpTxn txn, TSMBuffer buffer, TSMLoc hdr)
{
TSMLoc url = TS_NULL_MLOC;
TSMLoc dst = TS_NULL_MLOC;

struct {
char *ptr;
int len;
} strval = {nullptr, 0};

TSDebug("xdebug", "attempting to inject X-ParentSelection-Key header");

if (TSUrlCreate(buffer, &url) != TS_SUCCESS) {
goto done;
}

if (TSHttpTxnParentSelectionUrlGet(txn, buffer, url) != TS_SUCCESS) {
goto done;
}

strval.ptr = TSUrlStringGet(buffer, url, &strval.len);
if (strval.ptr == nullptr || strval.len == 0) {
goto done;
}

// Create a new response header field.
dst = FindOrMakeHdrField(buffer, hdr, "X-ParentSelection-Key", lengthof("X-ParentSelection-Key"));
if (dst == TS_NULL_MLOC) {
goto done;
}

// Now copy the parent selection lookup URL into the response header.
TSReleaseAssert(TSMimeHdrFieldValueStringInsert(buffer, hdr, dst, 0 /* idx */, strval.ptr, strval.len) == TS_SUCCESS);

done:
if (dst != TS_NULL_MLOC) {
TSHandleMLocRelease(buffer, hdr, dst);
}

if (url != TS_NULL_MLOC) {
TSHandleMLocRelease(buffer, TS_NULL_MLOC, url);
}

TSfree(strval.ptr);
}

static int
XInjectResponseHeaders(TSCont /* contp */, TSEvent event, void *edata)
{
Expand Down Expand Up @@ -384,6 +432,10 @@ XInjectResponseHeaders(TSCont /* contp */, TSEvent event, void *edata)
writePostBody(data);
}

if (xheaders & XHEADER_X_PSELECT_KEY) {
InjectParentSelectionKeyHeader(txn, buffer, hdr);
}

done:
TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
return TS_EVENT_NONE;
Expand Down Expand Up @@ -525,6 +577,9 @@ XScanRequestHeaders(TSCont /* contp */, TSEvent event, void *edata)
TSHttpTxnTransformedRespCache(txn, 0);
TSHttpTxnUntransformedRespCache(txn, 0);

} else if (header_field_eq("x-parentselection-key", value, vsize)) {
xheaders |= XHEADER_X_PSELECT_KEY;

} else if (isFwdFieldValue(std::string_view(value, vsize), fwdCnt)) {
if (fwdCnt > 0) {
// Decrement forward count in X-Debug header.
Expand Down
Loading