TSHTTPTXNP...RREADERGET(3ts)

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

✨ 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.

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