---
name: "TSMimeHdrFieldValueStringGet"
section: "3ts"
platform: "linux"
package: "trafficserver-dev"
version: "9.2.5+ds-0+deb12u4"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/TSMimeHdrFieldValueStringGet"
---

# TSMimeHdrFieldValueStringGet(3ts)

get HTTP MIME header values

## NAME

TSMimeHdrFieldValueStringGet - get HTTP MIME header values

## SYNOPSIS

```
#include <ts/ts.h>
```

- **const char \*TSMimeHdrFieldValueStringGet(*TSMBuffer* bufp, *TSMLoc* hdr, *TSMLoc* field, int idx, int \*value\_len\_ptr)**

  - **int TSMimeHdrFieldValueIntGet(*TSMBuffer* bufp, *TSMLoc* hdr, *TSMLoc* field, int idx)**

  - **int64\_t TSMimeHdrFieldValueInt64Get(*TSMBuffer* bufp, *TSMLoc* hdr, *TSMLoc* field, int idx)**

  - **unsigned int TSMimeHdrFieldValueUintGet(*TSMBuffer* bufp, *TSMLoc* hdr, *TSMLoc* field, int idx)**

  - **time\_t TSMimeHdrFieldValueDateGet(*TSMBuffer* bufp, *TSMLoc* hdr, *TSMLoc* field)**

  ## DESCRIPTION

MIME headers and fields can be components of request headers, response headers, or standalone headers created within a Traffic Server plugin. The functions here are all used to access header values of specific types, but it is up to the caller to know if a header has appropriate semantics for the API used. For all but *TSMimeHdrFieldValueStringGet()*, an appropriate data conversion algorithm is applied to the header field string.

All the APIs take a *TSMBuffer* marshal buffer argument *bufp*, and a *TSMLoc* argument *hdr* indicating the location of the HTTP headers. The required *field* argument is the locator of a specific header value, as returned by an accessor function such as *TSMimeHdrFieldFind()*.

Within the header field, comma-separated values can be retrieved with an index *idx* ranging from **0** to the maximum number of fields for this value; this maximum is retrieved using *TSMimeHdrFieldValuesCount()*. An *idx* value of **-1** has the semantics of retrieving the entire header value, regardless of how many comma-separated values there are. If a header is not comma-separated, an *idx* of **0** or **-1** are the same, but the latter is preferred.

*TSMimeHdrFieldValueStringGet()* returns a pointer to the header value, and populated *value\_len\_ptr* with the length of the value in bytes. The returned header value is not NUL-terminated.

## RETURN VALUES

All functions returns the header value with a type matching the respective function name. Using *TSMimeHdrFieldValueDateGet()* on a header which does not have date-time semantics always returns **0**.

## EXAMPLES

This examples show how to retrieve and copy a specific header.

```
#include <string.h>
#include <ts/ts.h>
int
get_content_type(TSHttpTxn txnp, char* buf, size_t buf_size)
{
  TSMBuffer bufp;
  TSMLoc hdrs;
  TSMLoc ctype_field;
  int len = -1;
  if (TS_SUCCESS == TSHttpTxnServerRespGet(txnp, &bufp, &hdrs)) {
    ctype_field = TSMimeHdrFieldFind(bufp, hdrs, TS_MIME_FIELD_CONTENT_TYPE, TS_MIME_LEN_CONTENT_TYPE);
    if (TS_NULL_MLOC != ctype_field) {
      const char* str = TSMimeHdrFieldValueStringGet(bufp, hdrs, ctype_field, -1, &len);
      if (len > buf_size)
        len = buf_size;
      memcpy(buf, str, len);
      TSHandleMLocRelease(bufp, hdrs, ctype_field);
    }
    TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdrs);
  }
  return len;
}
```

## SEE ALSO

**[TSAPI(3ts)](/TSAPI/3ts.md)**, **[TSMBufferCreate(3ts)](/TSMBufferCreate/3ts.md)**, **[TSMimeHdrFieldValuesCount(3ts)](/TSMimeHdrFieldValuesCount/3ts.md)**

## COPYRIGHT

2026, dev@trafficserver.apache.org
