Skip to main content

JMeter HTTP Header Manager: How It Works, Tested

JMeter HTTP Header Manager tested with 21 plans: which manager wins a clash, what JMeter sends by default, and how one header cut a 153 KB page to 36 KB.

JMeter HTTP Header Manager: How It Works, Tested

The JMeter HTTP Header Manager adds request headers, such as Authorization, Content-Type or User-Agent, to every HTTP request in its scope. Put one on the Thread Group and every sampler below it sends those headers. Put another on a single request to override one of them. Without one, JMeter sends only the few headers its HTTP client adds by itself.

We tested it in JMeter 5.6.2 against a small server that logged every request header it received, with 21 test plans: defaults, scope, clashes between managers, variables, tokens and a few headers that change what a load test measures. The manual covers the basics in two paragraphs. The tests below show what reaches the server when managers overlap, and which mistakes make a header disappear.

Key Takeaways

  • With no manager, JMeter’s default HTTP client sent only Connection, Host and User-Agent: Apache-HttpClient/4.5.14, plus Content-Length and Content-Type: text/plain; charset=UTF-8 on a POST or PUT with a body.
  • When two managers set the same header, the one closest to the request wins. On the same level, the first one in the tree wins, not the last.
  • Undefined variables are sent as typed: our server received the literal text Bearer ${token} on the login request.
  • Without Accept-Encoding: gzip, JMeter downloaded a real 153 KB HTML page uncompressed (153,543 bytes). With it, the same page took 35,678 bytes.
  • A header name with a trailing space got a 400 from a Node.js server. A Python server answered 200 but lost that header and every one after it.

What does the HTTP Header Manager do in JMeter?

It is a config element that holds a table of header names and values. Before each HTTP Request sampler runs, JMeter collects every manager of this kind in that sampler’s scope, merges their tables and adds the result to the request. A header with the same name as one the HTTP client sets usually replaces the client’s value, as User-Agent did in our runs. Connection and Host are exceptions, covered below. Unset headers are left to the client.

That last part matters more than it looks, because the client sends very little. This is what our server received with no manager at all, for the two HTTP implementations JMeter offers on the HTTP Request sampler:

RequestHttpClient4 (the default)Java
GETConnection: keep-alive, Host, User-Agent: Apache-HttpClient/4.5.14 (Java/11.0.19)Connection: keep-alive, Host, User-Agent: Java/11.0.19, Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
POST with a JSON bodythe above, plus Content-Length: 7 and Content-Type: text/plain; charset=UTF-8the above, plus Content-Length: 7 and Content-type: application/x-www-form-urlencoded

Neither sent Accept-Language or Accept-Encoding, and neither sent the JSON content type the body actually had. A browser sends the first two, and a web app’s JavaScript usually sets the JSON type itself. Anything your server reads from a header, from content negotiation to compression to API keys, has to be set in a manager.

How do you add a Header Manager in JMeter?

Right-click the element that should own it and choose Add > Config Element > HTTP Header Manager. Click Add to create a row and type the header name and value, one header per row. The manual suggests putting it on the Thread Group, like the HTTP Cookie Manager, so every request in that group gets the same headers. Add a second manager under one sampler only for headers that differ.

Placement is about scope, not order in the list. In one of our plans, a manager placed after the sampler in the same Thread Group still added its header to that sampler. A manager under a Simple Controller applies only to the samplers inside that controller, which is the cleanest way to give a group of requests their own headers.

The Load and Save As buttons store the table in a file and read it back, appending the loaded rows to the rows already there. The HTTP(S) Test Script Recorder can also create managers for you: with Capture HTTP Headers ticked, it adds one under each recorded sampler. The manual says it always removes Cookie and Authorization from those, and by default If-Modified-Since and If-None-Match as well. A recorded script with a token in it still needs that token added by hand, ideally from a variable.

Which manager wins when two set the same header?

The manager closest to the sampler wins. We gave the same header, X-Level, a different value on the Test Plan, the Thread Group, a Simple Controller and one sampler. Each request got the value from its nearest manager, and every header that was not in conflict reached the server merged from all levels. On the same level, the first manager in the tree wins.

Where the managers wereValue received
Test Plan + Thread Groupthe Thread Group’s
Test Plan + Thread Group + Simple Controllerthe controller’s
All of the above + one under the samplerthe sampler’s
Three managers side by side on the Thread Groupthe first one’s (we also renamed and reordered them to rule out the element names)
Two managers under the same samplerthe first one’s

The JMeter source (tag rel/v5.6.2) explains the pattern. When a sampler already holds a manager, HTTPSamplerBase.setHeaderManager merges the next one into it, and HeaderManager.merge keeps every existing header, adding only names it does not have yet. So the first manager applied keeps its values, and our runs show JMeter applies the closest one first: the merged headers reached the server in closest-first order. The manual’s wording, that a matching entry “replaces the previous entry”, describes the result from the sampler’s side.

The same merge code has two more effects we could see on the wire:

  • Names are compared without regard to case. A Thread Group manager with content-type: text/plain and a sampler manager with Content-Type: application/json produced one header, the sampler’s. HTTP field names are case-insensitive too (RFC 9110), so this matches what a server would see.
  • A repeated name can collapse in a merge. Two X-Dup rows in one manager reached the server as two headers. When that manager was merged into a closer one, only the first X-Dup arrived, because the merge skips a name it already holds.

How do you set Content-Type to application/json in JMeter?

Add a Header Manager under the sampler with Content-Type: application/json. Without it, a POST or PUT with a Body Data payload went out as text/plain; charset=UTF-8 with the default client, and a POST with the Java client went out as application/x-www-form-urlencoded. An API that checks the type can reject both, typically with 415 Unsupported Media Type.

The manual gives the same advice in its HTTP Request section: if you are not sending a file, “attach a Header Manager to the sampler and define the Content-Type there”. Note the sampler level. When we set content-type on the Thread Group instead, our GET requests carried it too, with no body to describe.

Two related rules come from the default HttpClient4 code. A Content-Length row in a manager is skipped, because JMeter computes the length from the body itself. When a file is sent as the whole body, with an empty Parameter name, its MIME Type sets the Content-Type unless a manager already sets one; for a multipart upload JMeter sends multipart/form-data whatever the manager says.

How do you use variables in a Header Manager?

Type a variable reference such as ${apiKey} or a function call such as ${__UUID()} as the value. JMeter resolves it each time the sampler runs, for that thread. In our runs a User Defined Variable resolved on every request, ${__UUID()} gave 8 different values across 8 requests, and ${__threadNum} gave each of the 2 threads its own number.

Per-user values work the same way. With a CSV Data Set Config feeding a variable called tenant and the header X-Tenant: ${tenant}, our 3 threads sent tenant-a, tenant-b and tenant-c, one each. Our guide to CSV data in JMeter tests covers the sharing and recycling options that decide which row each thread gets.

A variable that does not exist is not an error. JMeter sends the reference as plain text, so our server received the header X-Missing: ${notDefined}. That is a common way for bearer tokens to go wrong. We extracted a token from a login response and used Authorization: Bearer ${token}, first with the manager on the Thread Group, then on a Simple Controller around the API calls only:

Request (2 iterations)Manager on the Thread GroupManager on a controller around the API calls
Login, iteration 1Authorization: Bearer ${token} (literal text)no Authorization header
API call, iteration 1Bearer tok-78706Bearer tok-425
Login, iteration 2Bearer tok-78706 (last iteration’s token)no Authorization header
API call, iteration 2Bearer tok-78706Bearer tok-425

On the Thread Group, the login request itself carried the header: the literal text on the first pass and the previous iteration’s token after that. Our test server issued the same token each time; a real one would usually issue a new token and could reject the old one. A server that rejects an unknown token before it reads the credentials will fail that login. The controller version sends the header only where it belongs. The extraction step is covered in our guide to correlation in JMeter, and the full list of functions you can put in a header value is in JMeter functions.

Which headers change what a load test measures?

Some headers change the cost of each request, not just whether the server accepts it. Accept-Encoding decides whether responses arrive compressed, Connection: close decides whether every request opens a new TCP connection, and a browser-like header set adds a few hundred bytes to every request. Each of these changes the bytes or connections behind every request, which can move throughput and response times, so set them to match your real clients.

Header in the managerWhat we measured
None (default client)a 153,386-byte HTML page (a built article from this blog) downloaded as 153,543 bytes
Accept-Encoding: gzipsame page as 35,678 bytes, 4.3 times less; JMeter decompressed it, so a Response Assertion on the text still passed
None5 requests over 1 TCP connection
Connection: close5 requests over 5 connections (the first reused the open one, each later request opened a new one); every request carried two Connection headers: keep-alive from JMeter and close from the manager
8 browser headers (User-Agent, Accept, Accept-Language, Accept-Encoding, 3 Sec-Fetch-*, Upgrade-Insecure-Requests)468 bytes sent per GET instead of 122 for the same GET without them, so 346 more bytes on every request
Host: shop.example.testsent as shop.example.test:18089 by the default client, which keeps a non-default port from the URL; the Java client sent shop.example.test
User-Agent with an empty valuean empty User-Agent header, not a missing one

The compression row is the easiest one to miss. JMeter’s default client sent no Accept-Encoding, so a test without the header downloads pages uncompressed from servers that compress only on request, while real browsers ask for compression. Your bandwidth numbers and download times then describe a client nobody uses. The server side of this is covered in our note on how to enable gzip compression on NGINX.

To turn keep-alive off, untick Use KeepAlive on the HTTP Request instead of adding a Connection header. With the box unticked, JMeter sent a single Connection: close and opened 5 connections for 5 requests, without the contradictory pair.

Header Manager not working? Check these first

Most “header not sent” problems come from scope, a variable that did not resolve, or a typo in the header name. Before changing the plan, look at the request in a View Results Tree listener. Its Request panel shows the headers JMeter added, so you can tell whether a header is missing, empty or carries unresolved ${...} text. The manual notes it leaves out headers the HTTP client adds itself, such as Host.

  1. The manager is out of scope. It applies to samplers under its parent element. A manager under one sampler does nothing for its neighbours.
  2. A variable did not resolve. The request shows ${name} as text. Check the variable’s spelling and that whatever sets it ran first in the same thread.
  3. The header name ends in a space. It can come from a copied list or a hand-edited .jmx, and JMeter sends it as typed (see below).
  4. Another manager wins. A closer manager, or an earlier one on the same level, keeps its value. An empty value does not remove a header either: it sends the header with no value, as the manual notes.
  5. The header is a cookie. A Cookie header set this way is dropped once the HTTP Cookie Manager holds a cookie for that URL, as we measured in our HTTP Cookie Manager tests.

The trailing space is the hardest of these to spot, because the plan looks right. JMeter sent X-Trail-Name : v exactly as typed. Node.js 23’s HTTP parser rejected the request (HPE_INVALID_HEADER_TOKEN) and the server answered 400 Bad Request, as RFC 9112 requires. A Python http.server answered 200 but dropped that header and every one after it, Host and User-Agent included. Spaces around a value are also sent as typed, but RFC 9112 tells parsers to exclude them from the value.

Request headers on LoadFocus

The manager’s header rows travel with the .jmx file, so a cloud run sends the headers you set on your machine, including values that come from variables and uploaded CSV files.

LoadFocus runs JMeter test plans from uploaded .jmx files on cloud load generators in 25 regions, with the virtual users, duration and ramp-up set in the browser. For tests built in the browser without JMeter, each request has its own Headers list, and you can save a set as a preset or add browser-like headers with one click, as the headers and presets guide shows.

Frequently Asked Questions

What is the HTTP Header Manager in JMeter?

It is a JMeter config element that adds request headers, such as Authorization, Content-Type or User-Agent, to every HTTP request in its scope. Several managers can apply to one request: JMeter merges them, and when two set the same header, the one closest to the request wins.

How do I add a header to a request in JMeter?

Right-click the Thread Group, or a single HTTP Request, and choose Add > Config Element > HTTP Header Manager. Click Add and type the header name and value. On the Thread Group it applies to every request in the group; under one HTTP Request it applies to that request only.

How do I pass a variable in a JMeter header?

Type the variable reference as the header value, for example Authorization: Bearer ${token}. JMeter resolves it for each thread every time the request runs, so per-user tokens and CSV values work. If the variable does not exist, JMeter sends the text ${token} unchanged instead of failing.

How do I set Content-Type application/json in JMeter?

Add an HTTP Header Manager under the HTTP Request that sends the JSON body and set Content-Type to application/json. Without it, JMeter 5.6.2’s default HTTP client sends a Body Data payload as text/plain; charset=UTF-8, which an API that checks the type can reject, typically with 415 Unsupported Media Type.

Why is my JMeter Header Manager not working?

The usual causes are a manager outside the request’s scope, an unresolved variable sent as ${name}, a space after the header name, or a closer manager setting the same header. A Cookie header set in the manager is also dropped once the HTTP Cookie Manager holds a cookie for that URL.

Sources

  • HTTP Header Manager, HTTP Request and HTTP(S) Test Script Recorder: Apache JMeter User’s Manual, Component Reference, jmeter.apache.org/usermanual/component_reference.html, read 5 December 2026 (merging, empty values, Load and Save As, Content-Type for GET, DELETE, PUT and PATCH, the Host header as virtual host, headers removed when recording).
  • Using a Header Manager: Apache JMeter User’s Manual, Building an Advanced Web Test Plan, section 5.2, jmeter.apache.org/usermanual/build-adv-web-test-plan.html, read 5 December 2026.
  • Source code at tag rel/v5.6.2 of github.com/apache/jmeter: HeaderManager.java (merge), HTTPSamplerBase.java (setHeaderManager), HTTPHC4Impl.java (Connection, Host, Content-Length and Content-Type handling), read 5 December 2026.
  • Apache JMeter 5.6.3 change list, jmeter.apache.org/changes.html, read 5 December 2026: no Header Manager change, no change to how the HTTP Request builds headers (its one change, PR#6199, lets three checkboxes take ${...}), and no HttpClient 4 upgrade between 5.6.2 and 5.6.3.
  • RFC 9112, HTTP/1.1, section 5.1 (Field Line Parsing) and RFC 9110, HTTP Semantics, section 5.1 (Field Names), read 5 December 2026.
  • LoadFocus JMeter runs and request headers: loadfocus.com/jmeter-load-testing and loadfocus.com/docs/guides/load-testing/headers-and-manage-presets, read 5 December 2026.
  • Test runs: Apache JMeter 5.6.2 in non-GUI mode on Java 11.0.19, 21 test plans, against a local Python 3.10 http.server that logged every request header (62 requests; the compression test served a built article from this blog, 153,386 bytes of HTML), a raw socket listener that logged request bytes, and a Node.js 23.11.1 server with its default HTTP parser, on an Apple M1 Max, 5 December 2026.

Bogdan

Founder at LoadFocus

Bogdan builds and runs the tools this blog is about. He writes from what the products actually do in production, including the parts that break.

Weekly tips right in your inbox.

Don’t miss out on the latest testing tips and tricks, tools and news related to software testing.

Already +20,000 members in the list.

The Load Testing Platform with AI That Explains Your Results

Load test websites and APIs from 25 cloud regions, monitor page speed and uptime, and get AI analysis that explains your results in plain English.

Cloud load testing, website speed and API monitoring in one place.

Hi there! Can I share a cool thing I'm working on with you?

A software testing newsletter that sparks joy.

Our goal is to create helpful content for software developers and testers.

If you're not into it, you can unsubscribe instantly.