TSURLPERCENTENCODE(3ts)
π¦ TSURLPERCENTENCODE β the 3ts girlies' guide to URL percent encoding π
okay bestie, gather round, because this is the Apache Traffic Server URL percent encoding API and it is lowkey iconic. it's 3ts manual energy, so you already know it's C library business. no cap. β¨
πΈ SYNOPSIS πΈ
like, here's the vibe, literally verbatim:
#include <ts/ts.h>
TSReturnCode TSUrlPercentEncode(TSMBuffer bufp, TSMLoc offset, char *dst, size_t dst_size, size_t *length, const unsigned char *map)
TSReturnCode TSStringPercentEncode(const char *str, int str_len, char *dst, size_t dst_size, size_t *length, const unsigned char *map)
TSReturnCode TSStringPercentDecode(const char *str, size_t str_len, char *dst, size_t dst_size, size_t *length)
three functions. three little besties. each one doing its own thing and doing it well. π
π DESCRIPTION π
so first things first, context, because we're not doing anything unhinged without context:
The URL data structure is a parsed version of a standard internet URL. The Traffic Server URL API provides access to URL data stored in marshal buffers. The URL functions can create, copy, retrieve or delete entire URLs, and retrieve or modify parts of URLs, such as their host, port or scheme information.
like yes, host, port, scheme, the whole situation. it's a parsed URL, it lives in marshal buffers, and you can mess with any part of it. we love that for us. π«Ά
β¨ TSUrlPercentEncode() β¨
TSUrlPercentEncode() performs percent-encoding of the URL object, storing the new string in the dst buffer. The length parameter will be set to the new (encoded) string length, or 0 if the encoding failed.
so if it flops,lengthis just0. that's the tell. π
π¦ TSStringPercentEncode() π¦
TSStringPercentEncode() is similar but operates on a string. If the optional map parameter is provided (not NULL) , it should be a map of characters to encode.
optional map, bestie. skip it and it does its default thing; hand it a map and it's like "okay we're encoding these specifically". π
π TSStringPercentDecode() π
TSStringPercentDecode() perform percent-decoding of the string in the str buffer, writing to the dst buffer.
The source and destination can be the same, in which case the decoded string is written on top of the source string. The decoded string is guaranteed to be no longer than the source string, but will include a terminating null which, if there are no escapes, makes the destination one longer than the source.
In practice this means the destination length needs to be bumped up by one to account for the null, and a string can't be decoded in place if it's not already null terminated with the length of the destination including the null, but the length of the source not including the null. E.g.
static char const ORIGINAL[] = "A string without escapes, but null terminated";
char * source = TSstrdup(ORIGINAL); // make it writeable.
size_t length; // return value.
// sizeof(ORIGINAL) includes the null, so don't include that in the input.
static const size_t N_CHARS = sizeof(ORIGINAL) - 1;
TSReturnCode result = TSStringPercentDecode(source, N_CHARS, source, N_CHARS + 1, &length);
ink_assert(length == N_CHARS);
ok this is the part where you READ CAREFULLY, fr fr. the null terminator is doing the most. destination length = source length + 1 for the null. source length does not include the null. in-place decoding only works if it's already null terminated with the destination length including the null and the source length not including it. that's the whole tea. don't get it twisted. π
β RETURN VALUES β
All these APIs returns a TSReturnCode, indicating success (TS_SUCCESS) or failure (TS_ERROR) of the operation.
so it's a binary. slay or flop. that's it, that's the whole vibe check. π
π SEE ALSO π
the whole friend group. go read them too, iykyk. π§
π COPYRIGHT π
2026, dev@trafficserver.apache.org
ok that's the page!! version 9.2, dated Feb 12, 2026, and honestly it ate. go percent-encode something responsibly, bestie. mwah. ππβ¨
π¦ 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