# Cannot log a cookie with a dash in the name

**URL:** <https://www.ruby-forum.com/t/cannot-log-a-cookie-with-a-dash-in-the-name/217774>\
**Category:** NGINX\
**Created:** [March 12, 2012, 7:38pm UTC](https://www.ruby-forum.com/t/cannot-log-a-cookie-with-a-dash-in-the-name/217774 "2012-03-12T19:38:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 12, 2012, 7:38pm UTC](https://www.ruby-forum.com/t/cannot-log-a-cookie-with-a-dash-in-the-name/217774/1 "2012-03-12T19:38:43Z")

</div>

I am trying to log cookies but they have a dash in the name as such:

```
"Member-v1.0=$cookie_Member-v1.0"

```

My logs come through as:

```
Member-v1.0=--v1.0

```

Is there a work around?

I’ve tried wrapping the name in curly brackets and also using  
underscores but get an error about an unmatched bracket or no value.  
I’ve tried the following formats:

```
"Member-v1.0=${cookie_Member-v1.0}"

"Member-v1.0=$cookie_Member_v1.0"

"Member-v1.0=$cookie_Member_v1_0"

```

Any help would be greatly appreciated. I don’t want to have to move to  
Apache :\

Posted at Nginx Forum:

> **[Cannot log a cookie with a dash in the name](https://forum.nginx.org/read.php?2,223770,223770#msg-223770)**
>
> I am trying to log cookies but they have a dash in the name as such: "Member-v1.0=$cookie\_Member-v1.0" My logs come through as: Member-v1.0=--v1.0 Is there a work around? I've tried wrapping the name in curl

---

<div class="post-metadata">

**Author:** ![Hates\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f08c70/32.png) [@Hates\_S](https://www.ruby-forum.com/u/Hates_S)\
**Post date:** [March 12, 2012, 9:41pm UTC](https://www.ruby-forum.com/t/cannot-log-a-cookie-with-a-dash-in-the-name/217774/2 "2012-03-12T21:41:44Z")

</div>

On Mon, Mar 12, 2012 at 02:38:08PM -0400, Hates\_ wrote:

> I’ve tried wrapping the name in curly brackets and also using  
> Apache :  
> Currently, the names of nginx variables can be composed from  
> upper and lower English letters, digits and underscores. The  
> dash and dot characters are thus invalid.

Without patching the code, you should be able to log the entire  
value of the “Cookie” request header field with the $http\_cookie  
variable. It can also be useful if you have cookies whose names  
only differ in case as $cookie\_ doesn’t differentiate  
between upper and lower case:

http {  
server {  
location / {  
return 200 ‘http\_cookie=$http\_cookie cookie\_a=$cookie\_a  
cookie\_A=$cookie\_A\n’;  
}  
}  
}

$ curl -b ‘a=a;A=A’ [http://localhost:8000/test](http://localhost:8000/test)  
http\_cookie=a=a;A=A cookie\_a=a cookie\_A=a

---

<div class="post-metadata">

**Author:** ![Hates\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f08c70/32.png) [@Hates\_S](https://www.ruby-forum.com/u/Hates_S)\
**Post date:** [March 12, 2012, 9:58pm UTC](https://www.ruby-forum.com/t/cannot-log-a-cookie-with-a-dash-in-the-name/217774/3 "2012-03-12T21:58:33Z")

</div>

On Monday 12 March 2012 22:38:08 Hates\_ wrote:

> I’ve tried wrapping the name in curly brackets and also using  
> Apache :\

The map module may help:

map $http\_cookie $member\_cookie {  
default NONE;  
^Member-v1.0=(?P[^;]+) $mc;  
}

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Hates\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f08c70/32.png) [@Hates\_S](https://www.ruby-forum.com/u/Hates_S)\
**Post date:** [March 13, 2012, 10:28am UTC](https://www.ruby-forum.com/t/cannot-log-a-cookie-with-a-dash-in-the-name/217774/4 "2012-03-13T10:28:38Z")

</div>

Thanks a lot, the mapping worked. I just had to escape the semi colon to  
get it to work 🙂 Apache averted! 🙂

Posted at Nginx Forum:

> **[Re: Cannot log a cookie with a dash in the name](https://forum.nginx.org/read.php?2,223770,223790#msg-223790)**
>
> I am trying to log cookies but they have a dash in the name as such: "Member-v1.0=$cookie\_Member-v1.0" My logs come through as: Member-v1.0=--v1.0 Is there a work around? I've tried wrapping the name in curl

---

<div class="post-metadata">

**Author:** ![Hates\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f08c70/32.png) [@Hates\_S](https://www.ruby-forum.com/u/Hates_S)\
**Post date:** [March 13, 2012, 12:12am UTC](https://www.ruby-forum.com/t/cannot-log-a-cookie-with-a-dash-in-the-name/217774/5 "2012-03-13T00:12:06Z")

</div>

On Tuesday 13 March 2012 00:57:17 Valentin V. Bartenev wrote:  
[…]

> The map module may help:
> 
> map $http\_cookie $member\_cookie {  
> default NONE;  
> ^Member-v1.0=(?P[^;]+) $mc;  
> }

Oops.. must be:

```
map $http_cookie $member_cookie {
    default '';
    ~Member-v1\.0=(?P<mc>[^;]+) $mc;
}

```

wbr, Valentin V. Bartenev
