Headers generated based on current time

Hi Stéphane and others,

Thank you for your work on Gatling.

As the title suggests, I need AbstractHttpRequestBuilder to add different headers for each request depending on current time. It’d be perfect for the headers method to accept an anonymous function instead of a Map. Or I could use a feeder, but would need different feeders depending on the request method and url. Then I’d need some kind of feeder factory? It seems exceedingly complicated. Is there an easier way?

Thanks,
Vit

PS: I’m very new to Scala (and Java), please be patient with me.

Hm. There’s a thought.

Gatling has dollar variables. These are string based markers that are extrapolated by the gatling engine into values. As far as I understand it, at least.
Is it possible to have the value of such a thing be generated by a function call? That way you can have your anonymous functions anywhere you want …

Hi,

As Floris explained, most Gatling methods actually take functions parameters. We you pass a String, it gets implicitly compiled into a function thanks to the Expression Language compiler.
For example, “foo${bar}baz” will be turned into a function that take the Session attribute named “bar” in order to generate the concatenated String.

The things is that the headers method doesn’t work this way. Technically, type erasure gets in the way, and we haven’t found a solution yet (haven’t really searched too, this hasn’t been a priority).

But, you can use the header method instead. It only sets one header at a time, but it does take functions.

For example, instead of passing a hardcoded header value, you’d pass a function like:

(session: Session) => “now=” + System.currentTimeMillis

Cheers,

Stéphane

Thank you, Floris and Stéphane!