TSURLHOSTGET(3ts)

πŸ“¦
version 9.2.5 Β· 4 versions
, in ubuntu noble, ubuntu questing

πŸ’– TSUrlHostGet β€” the Traffic Server URL component retrieval API, bestie πŸ’–

ok so this is TSUrlHostGet(3ts) from the Apache Traffic Server manual, and it's literally the glow-up guide to pulling pieces out of a URL. no cap. let's get into it πŸ¦‹


✨ SYNOPSIS ✨

#include <ts/ts.h>

const char *TSUrlHostGet(TSMBuffer bufp, TSMLoc offset, int *length)

const char *TSUrlSchemeGet(TSMBuffer bufp, TSMLoc offset, int *length)

const char *TSUrlRawSchemeGet(TSMBuffer bufp, TSMLoc offset, int *length)

const char *TSUrlUserGet(TSMBuffer bufp, TSMLoc offset, int *length)

const char *TSUrlPasswordGet(TSMBuffer bufp, TSMLoc offset, int *length)

int TSUrlPortGet(TSMBuffer bufp, TSMLoc offset)

int TSUrlRawPortGet(TSMBuffer bufp, TSMLoc offset)

const char *TSUrlPathGet(TSMBuffer bufp, TSMLoc offset, int *length)

const char *TSUrlHttpQueryGet(TSMBuffer bufp, TSMLoc offset, int *length)

const char *TSUrlHttpParamsGet(TSMBuffer bufp, TSMLoc offset, int *length)

const char *TSUrlHttpFragmentGet(TSMBuffer bufp, TSMLoc offset, int *length)

like, eleven whole functions. she's serving range πŸ’…


🌸 DESCRIPTION 🌸

The URL data structure is basically a parsed, deconstructed version of a standard internet URL β€” think of it as the URL after it's been to therapy and worked through its feelings. The Traffic Server URL API hands you access to URL data that lives in marshal buffers. With these functions you can create, copy, retrieve or delete whole URLs, and also grab or tweak individual parts of them β€” like the host, the port, or the scheme info. iconic behavior, fr fr ✨

So here's the tea on the getters:

TSUrlSchemeGet(), TSUrlRawSchemeGet(), TSUrlUserGet(), TSUrlPasswordGet(), TSUrlHostGet(), TSUrlPathGet(), TSUrlHttpParamsGet(), TSUrlHttpQueryGet() and TSUrlHttpFragmentGet() β€” every single one of them retrieves an internal pointer to the specified portion of the URL out of the marshall buffer bufp. The length of the string they hand back gets dropped into length, and then you get a pointer to that URL portion. periodt. πŸŽ€

now, the scheme situation is a little nuanced, so pay attention bestie:

  • If a request URL does not have an explicit scheme, TSUrlRawSchemeGet() will return null and set length to zero.
  • TSUrlSchemeGet(), on the other hand, will return the scheme that corresponds to the URL type (HTTP or HTTPS) when there's no explicit scheme. she always has an answer πŸ’…

Then there's the port girlies:

TSUrlPortGet() retrieves the port number portion of the URL located at offset within the marshal buffer bufp. If there's no explicit port number in the URL, a canonicalized value is returned based on the URL scheme.

TSUrlRawPortGet() also retrieves the port number portion of the URL located at offset within the marshal buffer bufp. But β€” and this is the plot twist β€” if there's no explicit port number in the URL, zero is returned. no canonicalizing, no guessing, just raw honesty 😌


🌈 RETURN VALUES 🌈

Every single API here except TSUrlPortGet() and TSUrlRawPortGet() returns a string β€” and listen, this string is not guaranteed to be NULL terminated. 🚨 So you must always, always use the length value to figure out the actual length of the returned string. do not skip this step, it's giving undefined behavior energy and we don't want that πŸ™ˆ

TSUrlPortGet() just returns the port number as an integer, possibly canonicalized with 80 for HTTP and 443 for HTTPS schemes. And if there's neither port nor scheme information available in the URL, 0 is returned. period.

TSUrlRawPortGet(), by contrast, returns 0 in all cases where the port is not explicitly present in the URL. like, she's not doing extra credit. zero means zero. πŸ’€


πŸ¦‹ SEE ALSO πŸ¦‹

go read these too, they're all part of the same friend group:


2026, dev@trafficserver.apache.org


ok and that's the whole page bestie!! 🫢 you just read TSUrlHostGet(3ts) β€” Apache Traffic Server, version 9.2, dated Feb 12, 2026. slay, go write some plugins, mwah πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from