problem setting multiple cookies

Eric Wong normalperson at
Mon Jun 20 20:06:25 EDT 2011

Jason Su <jason at> wrote:
> Hey guys,
> When I try to set multiple cookies in one request, the 'Set-Cookies'
> header in the http response doesn't look right -- all the cookies are
> set without any line breaks.
> Looks like this:
> Set-Cookie:first=;; path=/; expires=Thu,
> 01-Jan-1970 00:00:00 GMTsecond=1;; path=/;
> expires=Sun, 20-Jun-2021 23:34:30 GMT

Which versions of Rails and Rack are you using?  How is your app
setting cookies?

Older versions of Rack may have specified a different delimiter (or an
Array).  Current versions only use "\n" inside a string, so it should be
something like:

  headers["Set-Cookie"] = "first=33; path=/\n" \
                          "second=; path=/\n" \
                          "third=; path=/"

Using Rack::Utils.set_cookie_header! (or a Rails-level wrapper) is
recommended, though.

> Should look more like this, which is what I got from a fresh Rails project test:
> Set-Cookie:first=33; path=/
> second=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT
> third=69; path=/

The response should have 3 individual Set-Cookie lines:

  Set-Cookie: first=33; path=/
  Set-Cookie: second=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT
  Set-Cookie: third=69; path=/

> In the first example, neither cookies (first/second) are set. The
> second example, all 3 cookies are set.
> I think it's happening somewhere here, but I can't figure out what's
> going on...

The code that does this transformation of the Rack header to the
client socket is here:

cgi_wrapper.rb is only for Rails <= 2.2, where it is called before

Eric Wong

More information about the mongrel-unicorn mailing list