TSHTTPTXNP...RREADERGET(3ts)
β¨ TSHttpTxnPostBufferReaderGet β¨
okay bestie, welcome to the ts/ts.h cinematic universe π this one's called TSHttpTxnPostBufferReaderGet β it's a function from the Apache Traffic Server 3ts manual, and yes it's as niche as it sounds, but it's SO useful, trust.
πΈ NAME πΈ
TSHttpTxnPostBufferReaderGet β the TSHttpTxnPostBufferReaderGet API function. that's it, that's the name, no notes π
π¦ SYNOPSIS π¦
#include <ts/ts.h>
TSIOBufferReader TSHttpTxnPostBufferReaderGet(TSHttpTxn txnp)
π DESCRIPTION π
so what does she do? she grabs the client request body for the transaction that txnp points at π«Ά and you read that body through the TSIOBufferReader she hands back to you.
important though, bestie, listen: the returned TSIOBufferReader is owned by the caller, meaning you have to free it with TSIOBufferReaderFree(). no cap, if you don't free it that's a leak and the vibe check fails π
also β and this is the part people miss β this function should be used in the handler for TS_HTTP_REQUEST_BUFFER_READ_COMPLETE_HOOK. that's her moment, that's her main character scene β¨
here's the example handler from the original, doing exactly that:
int
CB_Read_Request_Body_Hook(TSCont contp, TSEvent event, void* data) {
ink_assert(event == TS_EVENT_HTTP_REQUEST_BUFFER_COMPLETE);
auto txnp = reinterpret_cast<TSHttpTxn>(data);
TSIOBufferReader post_buffer_reader = TSHttpTxnPostBufferReaderGet(txnp);
int64_t read_avail = TSIOBufferReaderAvail(post_buffer_reader);
if (read_avail > 0) {
char *body_bytes = reinterpret_cast<char *>(TSmalloc(sizeof(char) * read_avail));
int64_t consumed = 0;
TSIOBufferBlock block = TSIOBufferReaderStart(post_buffer_reader);
while (block != NULL) {
int64_t data_len = 0;
const char *block_bytes = TSIOBufferBlockReadStart(block, post_buffer_reader, &data_len);
memcpy(body_bytes + consumed, block_bytes, data_len);
consumed += data_len;
block = TSIOBufferBlockNext(block);
}
// Now do something with body_bytes which contains the contents of the
// request's body.
}
// Remember to free the TSIOBufferReader.
TSIOBufferReaderFree(post_buffer_reader);
TSHttpTxnReenable(txnp);
return 0;
}
and if you want a whole working thing instead of just a snippet, example/plugins/c-api/request_buffer/request_buffer.c is a simple yet complete plugin that accesses HTTP request bodies. it ate, honestly π
π reminder from your girl: that TSIOBufferReaderFree(post_buffer_reader) line is not decoration, it is the whole point of being a responsible plugin dev.
π COPYRIGHT π
2026, dev@trafficserver.apache.org
and that's the whole page, periodt π this was Apache Traffic Server 9.2, dated Feb 12, 2026 β mwah, go free your buffer readers, ily π«Άβ¨
π¦ where this page comes from
- 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