← All articles
Apache

How to Extract Values from Response Header in JMeter?

JMeter can validate more than response bodies. In API tests, you may also need to capture a value returned in an HTTP response header and reuse it in a later request or assertion.

As an example, assume the API returns an ETag header:

ETag: 2666d92fa9ebf10250acdb235546f045

The goal is to extract only the header value and store it in a JMeter variable.

Configure the Regular Expression Extractor

In JMeter:

  1. Right-click the HTTP request and add Post Processors → Regular Expression Extractor.
  2. Select Main sample only.
  3. Select Response Headers as the field to check.
  4. Set Reference Name to a variable name such as eTagVariable.
  5. Set Regular Expression to:
   ETag:\s+(.+)

This matches the ETag header and captures everything after the colon and whitespace as group 1.

  1. Set Template to:
   $1$
  1. JMeter stores the captured value in the variable named eTagVariable.

You can then reference it elsewhere in the test plan as:

${eTagVariable}

Takeaway

The Regular Expression Extractor is useful when an API returns important state in response headers rather than the body. Once extracted into a JMeter variable, the value can be reused in subsequent requests, assertions, or other test logic.