Setting custom cookie.

1,070 views
Skip to first unread message

MLN

unread,
Jan 9, 2013, 7:28:24 AM1/9/13
to gat...@googlegroups.com
I want to set a custom cookie while making a HTTP request. any pointers to how this must be done?

Thanks

Stéphane Landelle

unread,
Jan 9, 2013, 7:41:44 AM1/9/13
to gat...@googlegroups.com
Hi,

Before answering your question, could you please explain your use case?
How come you send cookies that didn't come from the server in the first place?

Stéphane

2013/1/9 MLN <mlnkr...@gmail.com>

MLN

unread,
Jan 9, 2013, 7:46:46 AM1/9/13
to gat...@googlegroups.com
hi,

The user reaches my application via a hand-off from another application, which sets a certain cookie. I want to run the gatling tests starting from my application (after the hand-off).

MLN

Stéphane Landelle

unread,
Jan 9, 2013, 8:06:16 AM1/9/13
to gat...@googlegroups.com
OK, makes sense

Currently, you'll have to hack and manually initialize the CookieStore that's stored in the user Session.

.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)
})

You'll probably have to first use a Feeder in order to populate the TODOXXX values into the session, and then use session.getAttribute in order to retrieve them.

I guess it could be interesting to have a built-in for populating cookies... I will open an issue for 2.0.

Cheers,

Stéphane

2013/1/9 MLN <mlnkr...@gmail.com>

MLN

unread,
Jan 9, 2013, 8:27:20 AM1/9/13
to gat...@googlegroups.com
Thanks.

Stéphane Landelle

unread,
Jan 9, 2013, 8:28:56 AM1/9/13
to gat...@googlegroups.com
You're welcome.

For the record, I've opened a feature request:


2013/1/9 MLN <mlnkr...@gmail.com>

usul

unread,
Jan 9, 2013, 3:07:02 PM1/9/13
to gat...@googlegroups.com
Hi,
I have done this very easily with headers in a simulation : 

...
.headers(headers ++ Map("Cookie" -> "myCookieId=${VALUE_FROM_FEEDER}", ...)
...

Cheers

Stéphane Landelle

unread,
Jan 9, 2013, 4:47:54 PM1/9/13
to gat...@googlegroups.com
But if you do that, your "manual" cookie will only be sent on the request it's declared. Unless the server returns it in the response, it won't make it into the CookieStore, and won't be sent with the next requests.


2013/1/9 usul <fdus...@gmail.com>

usul

unread,
Jan 9, 2013, 5:08:58 PM1/9/13
to gat...@googlegroups.com
Yes, my needs are for "one shot" cookie :)

test user

unread,
Feb 7, 2020, 10:34:36 AM2/7/20
to Gatling User Group
how do I set multiple cookies using `.headers`. Is it possible?
Reply all
Reply to author
Forward
0 new messages