> ## Documentation Index
> Fetch the complete documentation index at: https://ngrok.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# HTTP Response Variables

> Reference documentation for HTTP response variables in Traffic Policy including status code, headers, and body content.

## Response Variables

The following variables are available under the `res` namespace:

| Name | Type | Description |
| - | - | - |
| [`res.content_encoding`](#rescontent-encoding) | `list[string]` | The encoding set in the `Content-Encoding` header for this response. |
| [`res.content_length`](#rescontent-length) | `int64` | The length of the content associated with the response. |
| [`res.content_type`](#rescontent-type) | `string` | The media type set in the `Content-Type` header for this response. |
| [`res.content_type.parameters`](#rescontent-typeparameters) | `map[string]string` | The parameters set in the `Content-Type` header for this response. |
| [`res.content_type.raw`](#rescontent-typeraw) | `string` | The `Content-Type` header for this response as a string. |
| [`res.cookies`](#rescookies) | `map[string][]cookie` | The HTTP cookie objects included in this response. If there are multiple cookies with the same name, they will be ordered by path length, with longest path first. |
| [`res.cookies[k][i].domain`](#rescookieskidomain) | `string` | The value of the `Domain` attribute of the cookie. |
| [`res.cookies[k][i].expires`](#rescookieskiexpires) | `timestamp` | The value of the `Expires` attribute of the cookie. |
| [`res.cookies[k][i].http_only`](#rescookieskihttp-only) | `boolean` | The value of the `HttpOnly` attribute of the cookie. |
| [`res.cookies[k][i].max_age`](#rescookieskimax-age) | `duration` | The value of the `MaxAge` attribute of the cookie. |
| [`res.cookies[k][i].name`](#rescookieskiname) | `string` | The name of the cookie. |
| [`res.cookies[k][i].path`](#rescookieskipath) | `string` | The value of the `Path` attribute of the cookie. |
| [`res.cookies[k][i].same_site`](#rescookieskisame-site) | `string` | The value of the `SameSite` attribute of the cookie. |
| [`res.cookies[k][i].secure`](#rescookieskisecure) | `boolean` | The value of the `Secure` attribute of the cookie. |
| [`res.cookies[k][i].unparsed_attributes`](#rescookieskiunparsed-attributes) | `map[string]string` | Any non-standard attributes of the cookie parsed as a map of names to values . |
| [`res.cookies[k][i].value`](#rescookieskivalue) | `string` | The value of the cookie. |
| [`res.headers`](#resheaders) | `map[string][]string` | The response headers parsed as a map of lower-case names to values. |
| [`res.location`](#reslocation) | `string` | The `Location` header value of this response. |
| [`res.status_code`](#resstatus-code) | `int32` | The status code of this response. |
| [`res.trailers`](#restrailers) | `map[string][]string` | The response trailers parsed as a map of lower-case names to values. |

### `res.content_encoding`

The encoding set in the Content-Encoding header for this response.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.content_encoding[0] == 'br'"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.content_encoding[0] == 'br'"
    ]
  }
  ```
</CodeGroup>

### `res.content_length`

The length of the content associated with the response.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.content_length != 0"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.content_length != 0"
    ]
  }
  ```
</CodeGroup>

### `res.content_type`

The media type set in the Content-Type header for this response.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.content_type == 'application/json'"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.content_type == 'application/json'"
    ]
  }
  ```
</CodeGroup>

### `res.content_type.parameters`

The parameters set in the Content-Type header for this response.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.content_type.parameters['charset'] == 'utf-8'"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.content_type.parameters['charset'] == 'utf-8'"
    ]
  }
  ```
</CodeGroup>

### `res.content_type.raw`

The Content-Type header for this response as a string.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.content_type.raw == 'application/json; charset=utf-8'"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.content_type.raw == 'application/json; charset=utf-8'"
    ]
  }
  ```
</CodeGroup>

### `res.cookies`

The HTTP cookie objects included in this response. If there are multiple cookies with the same name, they will be ordered by path length, with longest path first.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "size(res.cookies) > 0"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "size(res.cookies) > 0"
    ]
  }
  ```
</CodeGroup>

### `res.cookies[k][i].domain`

The value of the `Domain` attribute of the cookie.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.cookies['sessionId'][0].domain == 'nba.com'"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.cookies['sessionId'][0].domain == 'nba.com'"
    ]
  }
  ```
</CodeGroup>

### `res.cookies[k][i].expires`

The value of the `Expires` attribute of the cookie.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.cookies['sessionId'][0].expires > timestamp(time.now)"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.cookies['sessionId'][0].expires > timestamp(time.now)"
    ]
  }
  ```
</CodeGroup>

### `res.cookies[k][i].http_only`

The value of the `HttpOnly` attribute of the cookie.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.cookies['sessionId'][0].http_only"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.cookies['sessionId'][0].http_only"
    ]
  }
  ```
</CodeGroup>

### `res.cookies[k][i].max_age`

The value of the `MaxAge` attribute of the cookie.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.cookies['sessionId'][0].max_age > duration('24h')"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.cookies['sessionId'][0].max_age > duration('24h')"
    ]
  }
  ```
</CodeGroup>

### `res.cookies[k][i].name`

The name of the cookie.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.cookies['sessionId'][0].name == 'sessionId'"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.cookies['sessionId'][0].name == 'sessionId'"
    ]
  }
  ```
</CodeGroup>

### `res.cookies[k][i].path`

The value of the `Path` attribute of the cookie.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.cookies['sessionId'][0].path == '/"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.cookies['sessionId'][0].path == '/"
    ]
  }
  ```
</CodeGroup>

### `res.cookies[k][i].same_site`

The value of the `SameSite` attribute of the cookie.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.cookies['sessionId'][0].same_site"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.cookies['sessionId'][0].same_site"
    ]
  }
  ```
</CodeGroup>

### `res.cookies[k][i].secure`

The value of the `Secure` attribute of the cookie.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.cookies['sessionId'][0].secure"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.cookies['sessionId'][0].secure"
    ]
  }
  ```
</CodeGroup>

### `res.cookies[k][i].unparsed_attributes`

Any non-standard attributes of the cookie parsed as a map of names to values.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "size(res.cookies['sessionId'][0].unparsed_attributes) > 0"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "size(res.cookies['sessionId'][0].unparsed_attributes) > 0"
    ]
  }
  ```
</CodeGroup>

### `res.cookies[k][i].value`

The value of the cookie.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.cookies['sessionId'][0].value > 'value'"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.cookies['sessionId'][0].value > 'value'"
    ]
  }
  ```
</CodeGroup>

### `res.headers`

The response headers parsed as a map of lower-case names to values.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "'Fizz' in res.headers['baz']"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "'Fizz' in res.headers['baz']"
    ]
  }
  ```
</CodeGroup>

### `res.location`

The location header value of the response.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.location == '/index.html'"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.location == '/index.html'"
    ]
  }
  ```
</CodeGroup>

### `res.status_code`

The status code of this response.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "res.status_code >= 300"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "res.status_code >= 300"
    ]
  }
  ```
</CodeGroup>

### `res.trailers`

The response trailers parsed as a map of lower-case names to values.

<CodeGroup>
  ```yaml policy.yml theme={null}
  expressions:
    - "'fizz' in res.trailers['baz']"
  ```

  ```json policy.json theme={null}
  {
    "expressions": [
      "'fizz' in res.trailers['baz']"
    ]
  }
  ```
</CodeGroup>
