problem setting multiple cookies

Eric Wong normalperson at
Mon Jun 20 20:46:07 EDT 2011

Jason Su <jason at> wrote:
> Hey Eric,
> I'm using Rails 2.3.8, and Rack 1.1.2

Please don't top post, if you're just replying to the message in general
I'd rather you not quote at all.

> I'm setting cookies like this:
> cookies[:user_id] = { :domain => ".#{domain}", :value => "#{}",
> :expires => 10.years.from_now }

> How can I get the response to show up correctly, with individual
> Set-Cookie lines for each?

I wonder if it's a bug in older versions of Rails or Rack, there was
some confusion back in the day about how to handle multiple values
for a single header...

Can you try loading the following middleware in your app?

If it doesn't work, uncomment the 'p' statement and show us what data
structure is used for your headers.

---------------------- join_cookie.rb ---------------------------------
# Totally untested:
# usage (in
#   use JoinCookie
#   run
class JoinCookie <
  def call(env)
    status, headers, body =

    ## uncomment and show me the output of the next line if this doesn't work
    # p headers

    headers =
    case set_cookie = headers["Set-Cookie"]
    when Array
      headers["Set-Cookie"] = set_cookie.join("\n")

    [ status, headers, body ]

Eric Wong

More information about the mongrel-unicorn mailing list