Retrieve headers from the response

Good afternoon,

Is it possible to retrieve headers from the http response ?

I didn’t found it in the github wiki and API docs.

My use case is to automatically retrieve the ETag hash of a resource to send it in the next request (to have the 304/not change and mimic the client’s behavior).

Thank you,

Hi Raphaël,

You should be able to retrieve headers thanks to the headers checks : and then use saveAs, as usual :wink:


Thank you. Here is an example :

http(“main css”)
http(“main css 304”)
.header((“If-None-Match”, “${main.css-Etag}”))

The check succeeded, so I guess it works.

You can sort of “debug” your scenario if you want to.

Just use a simple action :

(s:Session) => println(s.getAttribute(“myKey”)); s

It’ll show the captured value.

Note that this should be used only in “dev mode”.


I tried to do a println like this but have a compilation error with 1.2.5 :

/usr/local/gatling/user-files/simulations/staging/CookieCache250.scala:41: error: type mismatch;
found : com.excilys.ebi.gatling.core.Predef.Session => Unit
required: com.excilys.ebi.gatling.core.action.builder.ActionBuilder
(s:Session) => println(s.getAttribute(“aisakosSegs”))

My aim is just to check a cookie, It seems to me that the simplest way is to get the value from session as it said here : that cookies are stored in the session

First, your simulation deson’t compile because you’re missing the ; s in the example below. As the Session class is immutable and one might want to edit it in a Session function, Session functions have to return a Session.

Then, cookies are stored in a CookieStore which is store in the Session, they are note store directly as attributes. The storage key for the CookieStore is “gatling.http.cookies”.
You cant directly print the CookieStore, it has a user-friendly toString method.



2012/8/9 usul <>

Hi !
The return of the header :slight_smile:

It seems that gatling can’t parse my cookie properly.
I have this in my scenario :

val scn = scenario(“Users Pool 2”)
http(“Get marker UP2”)
http(“Get image UP2”)
.headers(headers ++ Map(“Cookie” → “aisakosId=${BID}”, “User-Agent” → “Gatling/5.0 UP2 ${BID} ${SEGMENTS}”))
headerRegex(“Set-cookie”, (session: Session) => “aisakosSegs=” + session.getTypedAttributeString + “.*”)))

As you could see on
My feeder is used as it does, there’s the good values in the cookie and in the user-agent.
I’ve put those values in user-agent just for check.

And as you see it said : Check ‘exists’ failed, found None
But there’s the set cookie header :confused:

Perhaps because there’s some + in my cookie value ?



Hi François,

I’ll have a look tomorrow.

BTW, you could simply write:
headerRegex(“Set-cookie”, “aisakosSegs=${SEGMENTS}.*”)



2012/9/3 usul <>

Seems to me that I’ve alerady tested with ${} and it was not working, I’ll try again :wink:

I have same result with headerRegex(“Set-cookie”, “aisakosSegs=${SEGMENTS}.*”)


Sure, that’s just a more simple way of writing the same thing.
The problem is exactly what you suspected: there’s some special characters in your expression that have a regex meaning.

You have to escape them:
headerRegex(“Set-cookie”, (session: Session) => “aisakosSegs=” + session.getTypedAttributeString.replace("+", “\+”) + “.*”)))



PS: When will you stick to simple things?! 328.png

2012/9/3 François Dussert <>

And again you have the solution !
Thanks a lot



[1,2] client ← HTTP → server1
[3] client ← HTTP → server2

  1. client sends http request to get oauth token from server1
  2. server1 replies with oauth token in http header
  3. client sends http request to server2, with the oauth token (from server1) as a request header

Rather than check that the header is present, how can I use that header for my above work-flow?


Why not save the header with saveAs so you can add it so the next requests?

I’m running into same issue and not able to understand how to retrieve response headers ie; X-RateLimit-Limit etc.