Setting httpProtocol based on the results of an HTTP response

Hey, thanks for such a cool tool! I’m new to Gatling (and a year or so away from scala :confused: ) so perhaps I am thinking about my test setup (or everything) incorrectly.

I’d like to use httpProtocol to configure my requests. But, I don’t know the values that I want to put in the httpProtocol before the test runs, so I’m trying to figure out how to… lazily set up the httpProtocol, or… mutate the httpProtocol, or to set up a new httpProtocol… or something, after sending my first request. The first request comes back with the data I need to properly define the httpProtocol.

Basically, my first request is for an access_token as well as a user UUID. Following that, there will be 90 - 100 requests or so using the UUID in the url and requiring the access_token in the authorization header. I’ve found out how to use saveAs to put the access token and uuid into the session, but I don’t know how to tell gatling to use them in the subsequent requests other than explicitly putting a header and url in every request. Here’s a short version of what I’m trying to do…

val scn = scenario("load tests")

.exec(http("first request with important stuff in the response")

.exec( (session: Session) => {
// this is nonsense
val httpProtocol = http
.authorizationHeader("auth ${access_token}")

.exec(http("90 more of these exist")
.get(needs_the_user_id + "something else different per request")
.header("Authorization", needs_the_access_token)

// repeat variations of the above request with gets, posts, puts, etc...


Hm, a thought while typing this up, perhaps I could define custom functions for get, post, and put that configure everything properly… that seems reasonable, I guess. Well, if there’s any way to do this with httpProtocol, any guidance would be appreciated! Thanks!

fwiw, defining custom functions that returned an io.gatling.http.request.builder.HttpRequestBuilder made this more or less a non-issue. :slight_smile: basically

def get_rat ( page: String ) : io.gatling.http.request.builder.HttpRequestBuilder = {
  http("Get  " + nameFromPage( page ))
    .header("Authorization", "uses the ${access_token}")


For the record, your former approach can’t work:

  • HttpProcol is immutable
  • HttpProtocol is resolved when building the Simulation, i.e BEFORE running it
    And yes, a helper method is the best way. Add some implicit conversions and you’re king of the world. I’m considering making HttpRequestBuilder a case class to ease such use cases.


Since I’m guilty of doing this kind of stuff, I would support anything that makes this kind of magic easier to do. :slight_smile:

Done in 2.2 :slight_smile: