1

I have an http request in Gatling that gets executed 10 times:

val scnProxy = scenario("Access proxy")
  .exec(session => session.set("connect.sid", sessionId))
  .repeat(10) {
    exec(
      http("Access endpoint")
        .get("/my-api")
        .header(
          "Cookie",
          session => "connect.sid=" + session("connect.sid").as[String]
        )
        .check(status is 200)
    )
  }

For some reason, I get the intended response only on the first iteration. On every other iteration, I keep getting 401. So, I changed log level to TRACE to see what the problem is and found a weird behavior. For the first iteration, I get the header Cookie: connect.sid=... but for some reason, on second and other iterations, the cookie parameter gets overridden by the set-cookie of the previous request. Since Cookie header value is a string, it does not merge these cookies.

Is there a way that I can add a cookie instead of my cookie getting overriden?

Gasim
  • 7,615
  • 14
  • 64
  • 131

1 Answers1

1

Use the proper Gatling components for manipulating cookies.

Stéphane LANDELLE
  • 6,076
  • 2
  • 10
  • 12
  • I would like to use this but I am not sure how to use it when I need to read it from session. Could you please provide a snippet where the value returned from session can be used in `addCookie`? This does not work: `.exec(session => addCookie(Cookie("connect.sid", session("connect.sid").as[String])))` – Gasim Oct 16 '20 at 12:05
  • https://github.com/gatling/gatling/blob/master/gatling-http/src/test/scala/io/gatling/http/compile/HttpCompileTest.scala#L300 – Stéphane LANDELLE Oct 16 '20 at 12:40
  • the parameters can be functions or Gatling EL Strings – Stéphane LANDELLE Oct 16 '20 at 12:40