problem setting multiple cookies

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


Jason Su <jason at lookbook.nu> 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 => "#{user.id}",
> :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 config.ru):
#   use JoinCookie
#   run YourApp.new
class JoinCookie < Struct.new(:app)
  def call(env)
    status, headers, body = app.call(env)

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

    headers = Rack::Utils::HeaderHash.new(headers)
    case set_cookie = headers["Set-Cookie"]
    when Array
      headers["Set-Cookie"] = set_cookie.join("\n")
    end

    [ status, headers, body ]
  end
end
-----------------------------------------------------------------

-- 
Eric Wong


More information about the mongrel-unicorn mailing list