exec(http("request_secured")
.get("/portal/secured/")
.check(headerRegex("Set-Cookie", """XSRF-TOKEN=(.*)\s""").exists.saveAs("xsrfToken")))
Later on I want to use it in a request set in the header.
.exec(http("request_portal-entry")
.get("/portal/secured/template").headers(Map("X-XSRF-TOKEN" -> "${xsrfToken}")))
The problem is that the xsrfToken is URL encoded. I tried to call URLDecoder.decode but I simply don't know how to retrieve the value of the token from the session. The ${} expression is resolved somewhere deeper in the framework so I cannot simply pass this expression to the decode method.
Any ideas?
Cheers,Adam
.header("X-XSRF-TOKEN", session => session("xsrfToken").validate[String].map(URLDecoder.decode)))
--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
.check(headerRegex("Set-Cookie", """XSRF-TOKEN=(.*)\s""").transform(token => decode(token, "UTF-8").dropRight(1)).saveAs("xsrfToken")))
object Helper{
def setXsrfHeader(session:Session): Validation[String] = { getCookie("XSRF-TOKEN", session).map(c => URLDecoder.decode(c, "UTF-8")) match { case Some(value) => Success(value) case None => Failure("Unable to find XSRF-TOKEN cookie") } }
def getCookie(name:String, session:Session): Option[String] = { val cookieJar = session("gatling.http.cookies").as[CookieJar] cookieJar.get(Uri.create(baseUrl)).find(cookie => cookie.getName == name).map(_.getValue) }}
http("POST") .post("/myurl") .header("X-XSRF-TOKEN", Helper.setXsrfHeader)