response.set_cookie && response.delete_cookie do not work with get params present #72

Closed
webmanarmy opened this Issue Sep 29, 2010 · 4 comments

Comments

Projects
None yet
2 participants

when you have something like:

get '/my_url' do
  request.set_cookie('test', {:value => 'test_data'})
end

the cookie is set just fine

but if you have:

get '/my_url/:param1' do
  request.set_cookie('test', {:value => 'test_data'})
end

it will not work

Member

gnandretta commented Oct 4, 2010

Hi!

This isn't a bug. The cookie is set just fine in both cases. Well, not really... you're calling the set_cookie method on the request object but you need to call it on the response instead.

The problem with the second code example is that the new cookie only applies to urls that begins with '/my_url/'. You can see a better explanation of this in http://www.faqs.org/rfcs/rfc2109.html, but a simple solution might be

get '/my_url/:param1' do
  response.set_cookie('test', {:value => 'test_data', :path => '/'})
end

I'm sorry, that was a typo on my part. I was using response.set_cookie and having this issue. Does your code example work for you?

Member

gnandretta commented Oct 5, 2010

Yes, with curl -I localhost:4567/my_url/some_value I get

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 0
Set-Cookie: test=test_data; path=/
Connection: keep-alive
Server: thin 1.2.7 codename No Hup

Does it work for you? What ruby and sinatra versions are you using?

It is now working for me when I create a new project. I'm really not sure where the glitch is happening but until I have more details we can consider this not a glitch in sinatra.

Thank you for your help!

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment