Cookies with Goliath middleware

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.

About Me: I am a Atlanta based, native Android/IOS developer with AngularJS/Ruby experience and am founder of Polyglot Programming Inc.. Many of my projects focus on IOT and Wearables. You will often find me purr programming and I regularly speak at conferences around the world. I am available for hire! More Posts

Follow Me:
TwitterLinkedInGoogle Plus

I am a Atlanta based, native Android/IOS developer with AngularJS/Ruby experience and am founder of Polyglot Programming Inc.. Many of my projects focus on IOT and Wearables. You will often find me purr programming and I regularly speak at conferences around the world. I am available for hire!

Posted in Architecture, ruby

Leave a Reply

Your email address will not be published. Required fields are marked *

*