Goliath is a really quick multi-threaded web server. Recently I was trying to set and retrieve a cookie for a authentication module I am writing in it. So I googled, tried Rack::Utilities.cookies etc.. Nothing worked.
The solution (for me)
In my response method
def response(env)
[200, {'Set-Cookie' => ['lance=cookie']}, ["hello there"]]
end
This sets a cookie with a key of ‘lance’ and a value of ‘cookie’
To retrieve the value of a set cookie
def response(env)
my_cookies = env.HTTP_COOKIE
# do something meaningful with the cookies here.
end
You will need to do something meaningful to parse the string but it you now have cookie support.
Leave a Reply