# Access session data inside http byteArrayBody callback function

**URL:** <https://community.gatling.io/t/access-session-data-inside-http-bytearraybody-callback-function/113>\
**Category:** Gatling (Open-Source)\
**Created:** [July 11, 2012, 9:49am UTC](https://community.gatling.io/t/access-session-data-inside-http-bytearraybody-callback-function/113 "2012-07-11T09:49:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gabriel\_Magniez](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@Gabriel\_Magniez](https://community.gatling.io/u/Gabriel_Magniez)\
**Post date:** [July 11, 2012, 9:49am UTC](https://community.gatling.io/t/access-session-data-inside-http-bytearraybody-callback-function/113/1 "2012-07-11T09:49:22Z")

</div>

Hi,  
I’m not an expert in Scala nor Gatling for the moment, but I would like to know how can I access session attributes inside the byteArray callback function.  
My byte array is dependent from context variables different for each virtual user.

Regards,

---

<div class="post-metadata">

**Author:** ![Romain\_Sertelon](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@Romain\_Sertelon](https://community.gatling.io/u/Romain_Sertelon)\
**Post date:** [July 11, 2012, 10:05am UTC](https://community.gatling.io/t/access-session-data-inside-http-bytearraybody-callback-function/113/2 "2012-07-11T10:05:27Z")

</div>

Hi Gabriel,

If I’m right, there’s no way to use session values in byteArrayBody.

We could add this possibility by allowing you to pass a (Session =\> Array[Byte]) function, what do you think about this idea ?

Cheers,  
Romain

---

<div class="post-metadata">

**Author:** ![Gabriel\_Magniez](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@Gabriel\_Magniez](https://community.gatling.io/u/Gabriel_Magniez)\
**Post date:** [July 11, 2012, 10:28am UTC](https://community.gatling.io/t/access-session-data-inside-http-bytearraybody-callback-function/113/3 "2012-07-11T10:28:42Z")

</div>

Thanks for your answer.  
I think it’s the best way to realize it as the session can contains almost everything.

At the opposite, what is the easier way to handle the http response in byte array form?

Regards,

Gabriel

---

<div class="post-metadata">

**Author:** ![Romain\_Sertelon](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@Romain\_Sertelon](https://community.gatling.io/u/Romain_Sertelon)\
**Post date:** [July 12, 2012, 8:45am UTC](https://community.gatling.io/t/access-session-data-inside-http-bytearraybody-callback-function/113/4 "2012-07-12T08:45:21Z")

</div>

Hi Gabriel,

I’ve added the issue here : [https://github.com/excilys/gatling/issues/606](https://github.com/excilys/gatling/issues/606)

As for the response handling, what do need to do exactly ? As you may know, we provide checks, but they are not “byte-array-based”, they are based on strings.

If you provide us with more information about your use case, we may add support for byte-array-based checks.

Cheers,  
Romain

---

<div class="post-metadata">

**Author:** ![Gabriel\_Magniez](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@Gabriel\_Magniez](https://community.gatling.io/u/Gabriel_Magniez)\
**Post date:** [July 12, 2012, 9:15am UTC](https://community.gatling.io/t/access-session-data-inside-http-bytearraybody-callback-function/113/5 "2012-07-12T09:15:20Z")

</div>

Hi Romain,

I need to test a product that is based on a proprietary protocol sent over HTTP, in fact it is mainly based on custom encryption, so I need to be able to send binary data and to process data returned by the server which is binary too.  
So for the response, a function like saveAs, i.e. saveAsBytes to be able to process inside an “exec (s:Session)” manner would be perfect, morover the only way (before handling response with the Java API) to validate the response is with the HTTP status code, so I imagine writing it in gatling with “check(status.is(200)).saveAsBytes(“data”)”

Regards,

Gabriel

---

<div class="post-metadata">

**Author:** ![Romain\_Sertelon](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@Romain\_Sertelon](https://community.gatling.io/u/Romain_Sertelon)\
**Post date:** [July 12, 2012, 9:42am UTC](https://community.gatling.io/t/access-session-data-inside-http-bytearraybody-callback-function/113/6 "2012-07-12T09:42:27Z")

</div>

Hi,

Actually, the saveAs method should be called on the status method. Which forces us, seeing the current API, to have a check specialized in getting response as bytes and checking something on it.

I currently can’t think of a nice solution for your problem (I have some work to be done here ;)) but I’ll think of it !

If you have any idea, they are most welcome 🙂

Cheers,  
Romain

PS: It could be a check to verify that the body is not empty, and if not, save it either as bytes or as string… what do you think of it ?

---

<div class="post-metadata">

**Author:** ![Gabriel\_Magniez](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@Gabriel\_Magniez](https://community.gatling.io/u/Gabriel_Magniez)\
**Post date:** [July 12, 2012, 10:14am UTC](https://community.gatling.io/t/access-session-data-inside-http-bytearraybody-callback-function/113/7 "2012-07-12T10:14:25Z")

</div>

Yes, the presence of body can be a good solution. Is the last http status code stored in session, in order to handle the response data differently?

Cheers,

Gabriel

---

<div class="post-metadata">

**Author:** ![Romain\_Sertelon](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@Romain\_Sertelon](https://community.gatling.io/u/Romain_Sertelon)\
**Post date:** [July 12, 2012, 1:06pm UTC](https://community.gatling.io/t/access-session-data-inside-http-bytearraybody-callback-function/113/8 "2012-07-12T13:06:20Z")

</div>

The last HTTP status code isn’t saved (sorry, I forgot this one ;))

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [July 24, 2012, 9:18am UTC](https://community.gatling.io/t/access-session-data-inside-http-bytearraybody-callback-function/113/9 "2012-07-24T09:18:43Z")

</div>

So, should we open an issue for a new responseBodyBytes check (and maybe a responseBodyString)?  
That would be very easy to do, but beware that depending on your use case, it might have a big impact on your simulation (just like storing huge amounts of data in the HTTP session in a webapp is a bad idea).
