problem setting multiple cookies

Jason Su jason at lookbook.nu
Mon Jun 20 20:25:02 EDT 2011


Hey Eric,

I'm using Rails 2.3.8, and Rack 1.1.2

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?

Thanks again,

Jason



On Mon, Jun 20, 2011 at 5:06 PM, Eric Wong <normalperson at yhbt.net> wrote:
> Jason Su <jason at lookbook.nu> 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=; domain=.domain.com; path=/; expires=Thu,
>> 01-Jan-1970 00:00:00 GMTsecond=1; domain=.domain.com; 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... http://bogomips.org/unicorn.git/tree/lib/unicorn/cgi_wrapper.rb
>
> The code that does this transformation of the Rack header to the
> client socket is here:
>
> http://bogomips.org/unicorn.git/tree/lib/unicorn/http_response.rb
>
> cgi_wrapper.rb is only for Rails <= 2.2, where it is called before
> http_response.rb
>
> --
> Eric Wong
> _______________________________________________
> Unicorn mailing list - mongrel-unicorn at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mongrel-unicorn
> Do not quote signatures (like this one) or top post when replying
>


More information about the mongrel-unicorn mailing list