Get byte array response to process and store a session attribute

Hello gatling user group and developers,

I want to send a request and receive a byte[] body response. Based on this byte[] response I want to extract a value (using protobuf) and the reuse this value in another resquest.

After some hours search, I cannot find a possibility to extract the http response body as a byte array:

val httpConfig = http

val request = exec(http(“FirstRequest”)
.body(new ByteArrayBody((session: Session) => getFirstRequest(session)))
.check(, ???getByteResponse???))

val response = exec(http(“SecondRequest”)
.body(new ByteArrayBody((session: Session) => getSecondRequest(session)))
.check(, ???getByteResponse???))

val scn = scenario(“Request”).exec(request,response)

setUp(scn.inject(atOnce(1 user)))

Alternatively it would also be fine if I could set a value in getFirstRequest, that I can reuse in getSecondRequest:

private def getFirstRequest(session: Session): Array[Byte] = {

… setting a session attribute … (long)

… some protobuf stuff returning a byte array …


private def getSecondRequest(session: Session): Array[Byte] = {
var value= session(“value”).as[Long]

… some protobuf stuff using value from session and then returning byte array…


There’s a bodyString check that you can use with a transform step in order to get the bytes and deserialize them with Protobuf.

FYI, I’ve just pushed a bodyBytes check too:

Dear Stéphane,

thank you for your fast reply.

In my tries I also found the way to save the bodyString as a session variable. I guess since our server will response probably in UTF-8 I can transform it directly in the code, receiving it from the session.

Since I am really new to scala (Gatling is my firs try :)) is there a chance you can provide me a solution with transforming? I tried, but in my memories I must return a String, which at the end is the same as saveAs() the bodyString and catch it up in the second request.

Is there any chance that the a response object is available in the check method? Where you can just work with the “real” object instead of methods that already processed something.

Kind regards


Which version of Gatling do you use?

With current snapshot, it’s as simple as check(bodyBytes.saveAs(“bytes”))

With 2M3a, this would be check(bodyString.transform(.map(.getBytes(“UTF-8”))).saveAs(“bytes”))

Dear Stéphane,

is the M4 version available in maven?

I used the M3a maven archetype:


and have no idea what is the correct new version :slight_smile:

Kind regards


Honestly, I’m not convinced by this explanation. At all.
All UTF formats are reversible, meaning that the roundtrip bytes => char => bytes is lossless.
So, if the encoding you originally selected (see gatling.conf file) is UTF-8 (which is the default), you should be fine.

Then, current snapshot gives you bodyBytes check. You can grab it here:

Dear Stéphane,

I got the 2.0.0-SNAPSHOT version by using this new repository:



and setting


With your new bodyBytes method it worked properly. Using the bodyString and mapping it to bytes using UTF-8 did not work for protobuf.

Thanks a lot!

Kind regards


Glad to hear!