TSURLSTRINGGET(3ts)
π TSUrlStringGet β the traffic Server URL string representations API π
okay bestie, welcome to TSURLSTRINGGET(3ts), straight outta the Apache Traffic Server manual. this is where URLs stop being vibes and start being actual strings you can hand to people. buckle up π
β¨ SYNOPSIS β¨
#include <ts/ts.h>
char *TSUrlStringGet(TSMBuffer bufp, TSMLoc offset, int *length)
char *TSHttpTxnEffectiveUrlStringGet(TSHttpTxn txn, int *length)
TSReturnCode TSHttpHdrEffectiveUrlBufGet(TSMBuffer hdr_buf, TSMLoc
hdr_loc, char *buf, int64_t size, int64_t *length)
int TSUrlLengthGet(TSMBuffer bufp, TSMLoc offset)
void TSUrlPrint(TSMBuffer bufp, TSMLoc offset, TSIOBuffer iobufp)
πΈ DESCRIPTION πΈ
so the URL data structure? it's literally a parsed version of a standard internet URL. that's it, that's the whole thing. the Traffic Server URL API gives you access to URL data that lives in marshal buffers, and these functions can create, copy, retrieve or delete whole entire URLs, plus grab or tweak the little pieces β host, port, scheme, all of it. the full glow-up package π
π¦ TSUrlStringGet()
TSUrlStringGet() builds a string representation of the URL sitting at offset inside the marshal buffer bufp. (ngl bufp is actually superfluous and may be null β icon behaviour, honestly.) it stores the length of the allocated string in the parameter length. and plot twist: that's the exact same length that TSUrlLengthGet() returns. the returned string gets allocated by a call to TSmalloc() and must be freed by a call to TSfree() β do not skip this step, bestie, that's a leak π. if length is NULL then no attempt is made to de-reference it, so you're safe there. and heads up: the returned string is not guaranteed to have a null terminator β you must use length to display it correctly. no cap. π¨
π TSHttpTxnEffectiveUrlStringGet()
TSHttpTxnEffectiveUrlStringGet() is basically TSUrlStringGet()'s cooler sibling. there are exactly two differences:
- the source is the transaction
txn, and the URL gets retrieved from the client request in that transaction. - if the client request URL has a host, that URL is returned. otherwise, if there's a
"Host"field, the value of that field is used as the host in the returned URL.
this one is genuinely useful when you want to guarantee a URL that's as complete as possible given the specific request. obsessed. β¨
π§ TSHttpHdrEffectiveUrlBufGet()
TSHttpHdrEffectiveUrlBufGet() gives you the effective URL for any HTTP request β not just the client request. main character energy, no gatekeeping. if the request has a Host header field (and the URL doesn't already contain a host specifier), the host specifier the header provides gets inserted into the URL. also, the host and scheme in the returned URL will be normalized to lower case letters, which makes URL comparisons simple and fast. slay.
it prints the effective URL for the header specified by hdr_buf and hdr_loc into the buffer starting at buf. if the effective URL is longer than size, nothing is written to buf. and listen β that is not considered an error case. the function will still return TS_SUCCESS. it is the responsibility of the caller to check this result to determine if output was actually generated. the full length of the URL is always returned in *length when the function returns TS_SUCCESS. read that twice. π«Ά
the typical usage would be:
TSMBuffer hdr_buf;
TSMLoc hdr_loc;
TSHttpTxnServerReqGet(txn, &hdr_buf, &hdr_loc);
int64_t length;
char store[2048];
char *buf = store;
TSHttpHdrEffectiveUrlBufGet(hdr_buf, hdr_loc, buf, sizeof(store), &length);
if (length > sizeof(store)) {
buf = static_cast<char *>(malloc(length));
TSHttpHdrEffectiveUrlBufGet(hdr_buf, hdr_loc, buf, length, &length);
}
β TSUrlLengthGet()
TSUrlLengthGet() calculates the length of the URL located at offset within the marshal buffer bufp, as if it were returned as a string. and yes, this length will be the same as the length returned by TSUrlStringGet(). twins. π―
π TSUrlPrint()
TSUrlPrint() formats a URL stored in a TSMBuffer to a TSIOBuffer. capacity is added as needed to iobufp to print the entire URL, so it just keeps going until the whole thing is out. it's giving reliable. π
π₯ SEE ALSO π₯
TSAPI(3ts)TSmalloc(3ts)TSUrlCreate(3ts)TSUrlHostGet(3ts)TSUrlHostSet(3ts)TSUrlPercentEncode(3ts)
π COPYRIGHT π
2026, dev@trafficserver.apache.org
and that's the whole page, bestie! this was Apache Traffic Server 9.2, dated Feb 12, 2026 β go forth and free your strings with TSfree(), i'm begging you ππβ¨
π¦ where this page comes from
- ubuntu noble: trafficserver-dev 9.2.3+ds-1+deb12u1ubuntu0.1 Β· Apache-2.0
- ubuntu questing: trafficserver-dev 9.2.5+ds-1ubuntu2.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms