# Add second cookie to session.

**URL:** <https://community.gatling.io/t/add-second-cookie-to-session/2654>\
**Category:** Gatling (Open-Source)\
**Created:** [November 4, 2015, 9:30am UTC](https://community.gatling.io/t/add-second-cookie-to-session/2654 "2015-11-04T09:30:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcin\_Charezinski](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@Marcin\_Charezinski](https://community.gatling.io/u/Marcin_Charezinski)\
**Post date:** [November 4, 2015, 9:30am UTC](https://community.gatling.io/t/add-second-cookie-to-session/2654/1 "2015-11-04T09:30:07Z")

</div>

Hi (Gatling 2, I have read documentation)

I need too add second cookie to each header. For now I am able to add it as a static value in header.

```auto
val header_with_secondCookie = Map("Cookie" -> "firstCookie=01; secondCookie=${secondCookie}")
  

```

```auto
val postLoginAndPass = exec(
  http("request_1").post(uri2 + "/json/authenticate").headers(header_with_default_cookie)
    .body(ElFileBody("authBody.json")).asJSON
    .check(jsonPath("$.tokenId").saveAs("secondCookie"))   
)

val schouldGetWithNewSecondCookie = 
  exec(
    http("request_2")
    .get(uri2 + "/user")
    .headers(header_with_secondCookie)
  )

```

Maybe there is some way to add second cookie to session…?

---

<div class="post-metadata">

**Author:** ![Marcin\_Charezinski](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@Marcin\_Charezinski](https://community.gatling.io/u/Marcin_Charezinski)\
**Post date:** [November 5, 2015, 7:25am UTC](https://community.gatling.io/t/add-second-cookie-to-session/2654/2 "2015-11-05T07:25:45Z")

</div>

After DEBUGGING session I noticed that method  
exec(flushSessionCookies) works. Session cookies are dropped.

Now I need to add new cookie inside session, but method  
exec(addCookie(Cookie(“name”, “value”))) does not work at all.

`val scn = scenario("BasicSimulation") .exec(http("request_1").get("/")) .exec { session => println("My session before: " + session) session } .exec(addCookie(Cookie("name", "value"))) .exec { session => println("My session ater: " + session) session }`

So, sessions before and after are identical. No changes.  
How to add cookie to session manually, when addCookie figure doesn’t help.

```auto

```

---

<div class="post-metadata">

**Author:** ![notdryft](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/notdryft/32/1103_2.png) [@notdryft](https://community.gatling.io/u/notdryft)\
**Post date:** [November 5, 2015, 8:30am UTC](https://community.gatling.io/t/add-second-cookie-to-session/2654/3 "2015-11-05T08:30:12Z")

</div>

Hi,

What version of Gatling are you using ? This was a bug in previous versions that was corrected in 2.1.6 or 2.1.7.

Also, addCookie won’t work without a baseURL set on the protocol level.

Cheers.

---

<div class="post-metadata">

**Author:** ![Marcin\_Charezinski](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@Marcin\_Charezinski](https://community.gatling.io/u/Marcin_Charezinski)\
**Post date:** [November 5, 2015, 9:38am UTC](https://community.gatling.io/t/add-second-cookie-to-session/2654/4 "2015-11-05T09:38:30Z")

</div>

```auto
<properties>
   <maven.compiler.source>1.7</maven.compiler.source>
   <maven.compiler.target>1.7</maven.compiler.target>
   <scala.version>2.11.7</scala.version>
   <encoding>UTF-8</encoding>

   <gatling.version>2.2.0-M3</gatling.version>

   <scala-maven-plugin.version>3.2.2</scala-maven-plugin.version>
</properties>

```

Could you give me some tip how to set up baseURL and cookie together into the session?

My Cookie jar is sth like

`

gatling.http.cookies → CookieJar(Map(CookieKey(amlbcookie,[my.domain.com](http://my.domain.com),/) → StoredCookie(amlbcookie=01; [domain=my.domain.com](http://domain=my.domain.com); path=/,false,false,1446644285856))))  
`

And I need to add second cookie (or replace old one)

myNewCookieToken=${myNewCookieTokenValue}

W dniu czwartek, 5 listopada 2015 09:30:16 UTC+1 użytkownik Guillaume Corré napisał:

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [November 5, 2015, 10:14am UTC](https://community.gatling.io/t/add-second-cookie-to-session/2654/5 "2015-11-05T10:14:25Z")

</div>

We release milestones for our customers when they need them.  
You can use them, but at your own risks: they are not documented, and might contain bugs that are fixed in the master and/or the latest stable version (which is currently 2.1.7).

---

<div class="post-metadata">

**Author:** ![Marcin\_Charezinski](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@Marcin\_Charezinski](https://community.gatling.io/u/Marcin_Charezinski)\
**Post date:** [November 9, 2015, 10:18am UTC](https://community.gatling.io/t/add-second-cookie-to-session/2654/6 "2015-11-09T10:18:12Z")

</div>

Thanks for explanation.

After downgrade to 2.1.7 everything is OK.

W dniu czwartek, 5 listopada 2015 11:14:27 UTC+1 użytkownik Stéphane Landelle napisał:
