Skip to main content

JMeter HTTP Cookie Manager: How It Works, Tested

JMeter HTTP Cookie Manager tested with 21 plans: per-thread cookies, when they are cleared, and why a Max-Age=0 logout cookie was still sent by all 20 threads.

JMeter HTTP Cookie Manager: How It Works, Tested

The JMeter HTTP Cookie Manager stores the cookies a server sets and sends them back on later requests, the way a browser does. Each thread gets its own cookie store, so every virtual user keeps its own session. Without one, JMeter sends no cookies at all and a login that relies on a session cookie fails on the next request.

We tested it in JMeter 5.6.3 against a small server that logged the Cookie header of every request: 21 test plans, from a plain login to cookie deletion and clashes with the Header Manager. Most of it works as documented. Three results did not: when cookies are cleared between iterations, which deleted cookies JMeter keeps sending, and what happens to a Cookie header from the Header Manager. They explain many of the “not working” questions about it.

Key Takeaways

  • Add the manager to each Thread Group (or once at Test Plan level), under Add > Config Element. Without it, our login worked and the next request got a 401.
  • Each thread has its own cookies: 5 threads got 5 different session IDs. Cookies typed into the manager’s table are the exception, shared by every thread.
  • Unticking “Same user on each iteration” on the Thread Group does not clear cookies unless the manager’s own “Use Thread Group configuration to control cookie clearing” box is ticked too.
  • JMeter kept sending a cookie the server had deleted with Max-Age=0, or with an Expires date of 1 January 1970: 20 of 20 threads did, in both cases. An Expires date in 2000 worked.
  • A Cookie header set in the HTTP Header Manager disappears once the manager has its own cookie for that URL.

This config element does two jobs. It keeps every cookie a response sets, per thread, and adds the matching ones to each later request, applying the cookie’s domain, path and Secure rules. It also lets you define cookies by hand in its table, which every thread then sends. JMeter has no cookie handling of its own outside this element, so a plan without one sends no cookies.

Our test server issued a SESSIONID cookie on /login and answered /account with 200 only when that cookie came back. One thread, two requests:

SetupCookie sent to /account/account status
No managernone401
Manager, policy standard (the default)SESSIONID=<the issued value>200
Manager, policy ignoreCookiesnone401
Manager, 5 threadseach thread’s own SESSIONID (5 different values)200 for all 5

The ignoreCookies row matches the manual’s note that this policy is the same as having no manager. The last row is the per-thread store: each thread logged in and got its own session, which is what you want when every thread stands for a different user. Session cookies are one kind of value that has to flow from one response into the next request; for tokens in response bodies, see our guide to correlation in JMeter.

Right-click the Thread Group and choose Add > Config Element > HTTP Cookie Manager. Placed there, it applies to every HTTP request in that Thread Group. Put it at the Test Plan level instead and it covers all Thread Groups, and each thread still keeps its own cookies. The settings are few:

SettingDefaultWhat it does
Clear cookies each iteration?OffDeletes the cookies received from servers when the Thread Group starts a new loop. Hand-typed cookies stay.
Use Thread Group configuration to control cookie clearingOffHands that decision to the Thread Group’s “Same user on each iteration” box, and greys out the option above.
Cookie PolicystandardHow Set-Cookie headers are parsed and matched. standard is the default since JMeter 3.0; ignoreCookies turns cookie handling off.
User-Defined CookiesemptyCookies you add by hand, with a name, value, domain and path. Every thread sends them.

The manual also lists an Implementation setting, HC4CookieHandler (Apache HttpClient 4.5). It is the only one in JMeter 5.6.3, and the GUI no longer shows it. Use one manager per scope. The manual warns that with two managers in scope there is no way to say which one a sampler uses, and a cookie stored by one is not visible to the other. The manager’s scope follows the same rules as every other config element; our post on the execution order of JMeter elements covers it.

When does JMeter clear cookies between iterations?

Only in two cases. Either “Clear cookies each iteration?” is ticked and “Use Thread Group configuration” is not, or the manager’s “Use Thread Group configuration” box is ticked and the Thread Group’s “Same user on each iteration” box is not. Any other combination keeps the cookies for the thread’s whole life, even when the Thread Group says each iteration is a new user.

We ran a login inside a Once Only Controller, so it happened in the first iteration only, followed by a request to /account in each of 3 iterations:

Manager settingsThread Group “Same user on each iteration”/account in iterations 1, 2, 3
Both boxes off (defaults)Ticked (default)200, 200, 200
Clear cookies each iteration tickedTicked200, 401, 401
Both boxes offUnticked200, 200, 200
Use Thread Group configuration tickedUnticked200, 401, 401
Use Thread Group configuration and Clear cookies both tickedTicked200, 200, 200

The third row is the trap. Unticking “Same user on each iteration” reads like “start each loop as a new user”, and it does reset the connections, but the manager ignores it unless you tick its own “Use Thread Group configuration” box. The last row shows the other side: once that box is ticked, the “Clear cookies each iteration?” setting is ignored, which is why the GUI greys it out. JMeter 5.6.3’s source has the same logic in CookieManager.testIterationStart. What else changes when each iteration is a new user is in our JMeter thread groups guide and in our test of connection reuse between iterations.

The Once Only Controller matters here: with cookies cleared every loop, a login that runs only once leaves iterations 2 and 3 without a session. Either log in every iteration or keep the cookies. Our post on JMeter logic controllers shows the Once Only Controller in a test plan.

Which cookies does JMeter send back?

The ones whose domain, path and Secure flag match the request, as a browser would. A cookie set with Path=/api went to /api/data and not to /other. A cookie marked Secure was never sent over plain HTTP. Cookies with an empty value are dropped unless you change a property, and hand-typed cookies go only to the domain you give them.

From the runs:

  • Path: APIKEY (set with Path=/api) was sent to /api/data only.
  • Secure: SECURE_SID (set with Secure) was not sent on any later request, because the test ran over http://. Test against HTTPS or the cookie never comes back.
  • Empty values: a server setting EMPTY= with no value got nothing back. With -JCookieManager.delete_null_cookies=false, JMeter stored it and sent EMPTY= on the next request.
  • Hand-typed cookies: TENANT=acme with domain 127.0.0.1 went out on every request from both threads, next to each thread’s own SESSIONID. The same table’s WRONGHOST=x for domain example.com was never sent to our server. The domain is a host name, without http://, and the port is ignored.

Cross-domain cookies we did not test: the manual says JMeter refuses cookies set for another domain, and that the property CookieManager.check.cookies=false turns that check off.

Because JMeter 5.6.3 removes a cookie only when the server’s delete instruction carries an expiry date that is already past when JMeter reads it. Max-Age=0 gives an expiry of “now”, and JMeter keeps any cookie whose expiry is not before the current millisecond. An Expires date of 1 January 1970 gives an expiry of 0, which JMeter uses to mean “session cookie, keep it”.

We logged 20 threads in, sent them to a logout URL, then requested /account. Only the deletion header changed between runs:

Logout response headerLater requests still carrying SESSIONID
Set-Cookie: SESSIONID=deleted; Path=/; Max-Age=020 of 20
Set-Cookie: SESSIONID=deleted; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT20 of 20
Set-Cookie: SESSIONID=deleted; Path=/; Expires=Sat, 01 Jan 2000 00:00:00 GMT0 of 20

JMeter 5.6.2 gave the same three results. All 20 /account requests still got 401 in every run, because the cookie that stayed behind held the value deleted, not the old session ID. JMeter did replace the value, but kept the cookie. That was harmless here, because our server checked the value. Against a server that only checks whether a session cookie is present, the logged-out thread would still look logged in.

A related result: JMeter does not check expiry when it sends. A cookie set with Max-Age=1 was still sent 2.52 seconds later. In HC4CookieHandler, cookies are matched to a request by domain, path and the Secure flag only; the expiry is checked once, when the Set-Cookie header arrives. If your test depends on cookies expiring during a run, it will not see them expire. Clear them with the iteration settings above.

Set the JMeter property CookieManager.save.cookies=true, in user.properties or with -JCookieManager.save.cookies=true on the command line. Every cookie a thread receives is then also stored as a variable named after the cookie with a COOKIE_ prefix, so the value of SESSIONID is ${COOKIE_SESSIONID}.

Without the property, the variable does not exist and JMeter leaves ${COOKIE_SESSIONID} in the request as literal text. In our run that made the request fail before it was sent: Non HTTP response code: java.net.URISyntaxException, Illegal character in query at index 32, because { is not allowed in a URL. With the property set, the same request carried the session ID. Our post on JMeter Non HTTP response code errors covers that family of errors. The COOKIE_ prefix comes from the property CookieManager.name.prefix; to drop it, the manual says to set it to one or more spaces.

You can, but JMeter drops that header once its cookie store holds a cookie for the same URL. We added Cookie: MANUAL=m1 in an HTTP Header Manager and ran two requests. With the manager in scope, the first request carried MANUAL=m1, and the second carried only the SESSIONID from the first response: MANUAL=m1 was gone. Without one, both requests carried MANUAL=m1.

So pick one way per cookie. For a fixed cookie that every thread needs, such as a feature flag or a tenant ID, type it into the manager’s own table, where it is sent next to the cookies the server sets. Keep the Header Manager’s Cookie header for plans without a manager.

Most failures we saw came from a few causes: no manager in scope, cookies cleared while the login runs only once, a Secure or path rule that stops the cookie, or a server deleting the cookie with Max-Age=0. Read the request side of View Results Tree (or log the Cookie header on the server) before changing anything:

SymptomLikely cause
No Cookie header on any requestNo manager in scope, or the policy is ignoreCookies
Works in iteration 1, 401 from iteration 2Cookies cleared each iteration while the login runs once
Each loop should be a new user, but the session carries over”Same user on each iteration” unticked without “Use Thread Group configuration” ticked in the manager
One cookie never comes backIts Secure flag on an HTTP test, a Path that does not match, or an empty value
A logged-out session still sends its cookieThe server deletes it with Max-Age=0 or a 1970 Expires date
A hand-made Cookie header vanishesThe manager replaced it
${COOKIE_name} shows up literallyCookieManager.save.cookies=true is not set

Session cookies on LoadFocus

Cookie handling, with every manager setting, is part of the .jmx file, so a session-based test needs the same cookie setup in the cloud as on your machine. The CookieManager.* properties are the exception: they live in user.properties or on the command line, not in the plan.

LoadFocus runs JMeter tests from uploaded .jmx files, unchanged, on cloud load generators in 25 regions, and lets you set the virtual users, duration and ramp-up in the browser. Before uploading, the free JMeter script validator checks the .jmx for errors, and the glossary explains how APIs use cookies.

Frequently Asked Questions

It is a JMeter config element that stores the cookies servers set and sends them back on later requests, like a browser. Each thread keeps its own cookies, so each virtual user has its own session. Without one, JMeter sends no cookies, and logins that depend on a session cookie fail.

Right-click your Thread Group and choose Add > Config Element > HTTP Cookie Manager. The defaults work for most session logins: policy standard, cookies kept across iterations. Tick “Clear cookies each iteration?” only if every loop logs in again, and add cookies to its table only when every thread should send the same value.

Does each JMeter thread have its own cookies?

Yes. Cookies that servers set are stored per thread: in our test, 5 threads logged in and each sent back its own session ID. Cookies typed into the manager’s table are the exception, because every thread sends those. Within one thread, the cookies last across iterations unless the clearing settings remove them.

The usual causes are a manager outside the sampler’s scope, the ignoreCookies policy, a Secure cookie sent over HTTP, a path that does not match, or cookies cleared each iteration while the login runs once. JMeter 5.6.3 also keeps cookies deleted with Max-Age=0 or a 1970 expiry date. Unticking “Same user on each iteration” clears nothing unless the manager’s “Use Thread Group configuration” box is ticked, and a Cookie header from the Header Manager is dropped once the manager holds its own cookie for that URL.

Set the property CookieManager.save.cookies=true in user.properties or with -J on the command line. JMeter then saves each received cookie as a variable with a COOKIE_ prefix, so a cookie named SESSIONID is available as ${COOKIE_SESSIONID}. Without the property, the variable stays unresolved.

Sources

  • HTTP Cookie Manager, HTTP Header Manager and Thread Group: Apache JMeter User’s Manual, Component Reference, jmeter.apache.org/usermanual/component_reference.html, read 3 December 2026 (per-thread storage, COOKIE_ variables, shared hand-typed cookies, one manager per scope, ignoreCookies).
  • Cookie properties (CookieManager.save.cookies, check.cookies, delete_null_cookies, name.prefix): Apache JMeter User’s Manual, Properties Reference, jmeter.apache.org/usermanual/properties_reference.html, read 3 December 2026.
  • Source code at tag rel/v5.6.3 of github.com/apache/jmeter: CookieManager.java (iteration clearing), HC4CookieHandler.java (expiry check on receipt, matching on send), CookiePanel.java and messages.properties (GUI labels), read 3 December 2026.
  • LoadFocus JMeter runs and the script validator: loadfocus.com/jmeter-load-testing and loadfocus.com/jmeter-script-validator, read 3 December 2026.
  • Test runs: Apache JMeter 5.6.3 (SHA-512 checked) in non-GUI mode on Java 11.0.19, against a local Python 3.10 server that logged the Cookie header of every request, on an Apple M1 Max, 3 December 2026. The three deletion runs, the Header Manager clash run and the “Use Thread Group configuration” iteration run were repeated on JMeter 5.6.2 with the same results.

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.