Quoted cookie values causing issues with automagically adding cookies to subsequent requests

Hi,

I’m writing some stress tests for a Spray server (1.0-M7) which is sending back some cookies, that I would like Gatling (1.4.7) to pass on subsequently (as it does). What I’m seeing is that Spray sends back the cookie values quoted, and then when Gatling attaches it to a subsequent request it is malformed because of the extra quotes. Something like this:

Cookie: sessionAuth="“6cc44b6b-8a95-4b03-a2ad-b9ef87b34d42"”; $Path="/"; $Domain=localhost

It looks like Spray has changed their implementation recently to not quote the values (https://github.com/spray/spray/pull/217) but it has not yet made it into a milestone release and we do not want to use a nightly build at this point.

I’m thinking of getting round this by extracting the cookie value myself in Gatling, and then manually putting it into the cookie store, as described here: https://groups.google.com/forum/#!searchin/gatling/custom$20cookie/gatling/24pttq7kzHo/bAi6iW1X_VAJ, with something like this:

.exec(session => {
import java.net.URI
import com.ning.http.client.Cookie
import com.excilys.ebi.gatling.http.cookie.CookieStore

val customCookie = new Cookie(“TODOdomain”, “TODOname”, “TODOvalue”, “TODOpath”, 100000000, false)
val cookieStore = CookieStore(new URI(“TODOuri”), List(customCookie))
session.set(“gatling.http.cookies”, cookieStore)
})

And pulling out the cookie value to set with something like:
headerRegex(“Set-cookie”, “”“sessionAuth=”(.)";.""").saveAs(“sessionAuth”)

My question is if this is the best approach, or if there is a better way?

Thanks

Tim

Hi Tim,

Let me check, that’s probably AsyncHttpClient that doesn’t properly handle quoted cookie values.

Your workaround would probably work, but it might be better to get this fixed in the right place, in AHC. Hopefully, I’m a committer there too, so that might speed up things. :wink:

Stay tuned,

Stéphane

Could you provide the exact Set-Cookie header that spray returns, please?

Sure, and thanks for looking into this so quickly! :slight_smile:

The header I get back is:

HTTP/1.1 200 OK
Set-Cookie: sessionAuth=“d8ee0b7e-698d-4859-864f-12e04ed85d1f”; Path=/

Also as an aside, I have been able to get it to work ok by manipulating the cookie jar, like this:

import java.net.URI
import com.ning.http.client.Cookie
val saveCookie = exec(session => {
val sessionAuthCookie = new Cookie(“localhost”, “sessionAuth”, session.getAttribute(“sessionAuth”).toString, “/”, -1, false)
val uri: URI = new URI(null, “localhost”, “/”, null)
val cookieJar = CookieJar(uri, List(sessionAuthCookie))
session.setAttribute(“gatling.http.cookies”, cookieJar)
})

Tim

Glad to hear!
You managing to have the workaround working gives me more breath to fix this properly in AHC.

Hi Tim,

I’ve pushed a fix on AHC for your problem. The AHC release will probably be tomorrow, but I’ve deployed a SNAPSHOT in our repository: http://repository.excilys.com/

Could you give it a try? Version is 1.7.14.custom.

Cheers,

Stéphane

Hi Stéphane,

Of course, no problem :slight_smile:

I’ve just tested the snapshot but am getting an IllegalAccessError. It looks like the Gatling CookieJar needs access to setPorts() in AHC, but that is now a private method. This is the stack trace I get:

Uncaught error from thread [GatlingSystem-akka.actor.default-dispatcher-8] shutting down JVM since ‘akka.jvm-exit-on-fatal-error’ is enabled for ActorSystem[GatlingSystem]
java.lang.IllegalAccessError: tried to access method com.ning.http.client.Cookie.setPorts(Ljava/lang/Iterable;)V from class com.excilys.ebi.gatling.http.cookie.CookieJar$$anonfun$1
at com.excilys.ebi.gatling.http.cookie.CookieJar$$anonfun$1.apply(CookieJar.scala:77)
at com.excilys.ebi.gatling.http.cookie.CookieJar$$anonfun$1.apply(CookieJar.scala:71)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:76)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:233)
at scala.collection.immutable.List.map(List.scala:76)
at com.excilys.ebi.gatling.http.cookie.CookieJar.add(CookieJar.scala:71)
at com.excilys.ebi.gatling.http.cookie.CookieJar$.apply(CookieJar.scala:39)
at com.excilys.ebi.gatling.http.cookie.CookieHandling$.storeCookies(CookieHandling.scala:39)
at com.excilys.ebi.gatling.http.ahc.GatlingAsyncHandlerActor.com$excilys$ebi$gatling$http$ahc$GatlingAsyncHandlerActor$$processResponse(GatlingAsyncHandlerActor.scala:200)
at com.excilys.ebi.gatling.http.ahc.GatlingAsyncHandlerActor$$anonfun$receive$1.apply(GatlingAsyncHandlerActor.scala:108)
at com.excilys.ebi.gatling.http.ahc.GatlingAsyncHandlerActor$$anonfun$receive$1.apply(GatlingAsyncHandlerActor.scala:84)
at akka.actor.Actor$class.apply(Actor.scala:318)
at com.excilys.ebi.gatling.http.ahc.GatlingAsyncHandlerActor.apply(GatlingAsyncHandlerActor.scala:70)
at akka.actor.ActorCell.invoke(ActorCell.scala:626)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197)
at akka.dispatch.Mailbox.run(Mailbox.scala:179)
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:516)
at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)
at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479)
at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)

Cheers
Tim

Aw, my fault. I guess I will make those methods private only in AHC 2…
Let me fix this.

Should be fixed now. Could you try with 1.7.14.custom2, please?

Cheers,

Stéphane

Actually, AHC 1.7.14 has been officially release.

Thanks Stéphane, I’ve upgrade to AHC 1.7.14 and everything is working great :slight_smile:

Great!
Thanks for your feedback.