EL ternary expression

Is there any way to use ternary expressions within the Gatling EL ?

I’m using Gatling 2.2.2 and trying to send a header value only when it is provided, such as:

.header("${userToken.exists()?Authorization:}", “${userToken.exists() ? Bearer ${userToken}:’’}”)

When the session value “userToken” does not exists an empty header is setted, however the EL engine doesn’t seem to understand this kind of notation (or I’m doing something wrong)

Is this the best aproach?

The purpose is to create a single “page object” that behaves with whatever data it is provided (for some details only) so I don’t need to duplicate code just because the virtual user is logged in.

Thank you

I think I found a solution:
Accordingly to session API we can use Optionals as such:

.header(“Authorization”, {session => session(“userToken”).asOption[String].getOrElseString})

It worked, however I’m curious if this is the best approach to follow.


Thank you!!