Re: mod_ruby Apache::* tutorial
Kirk Haines <[email protected]> Fri, 2 Jun 2006 11:05:37 -0600
| Newsgroups | gmane.comp.apache.mod-ruby |
|---|---|
| Message-ID | <[email protected]> |
On Friday 02 June 2006 10:36 am, Mat Schaffer wrote:
> Is there anyone working on a cleaner way to access these things?
> Having to do cookies via manual header lines is a pretty significant
> barrier to entry, IMHO.
Take a look at WEBrick::Cookie. It lives under the WEBrick namespace, but is
not coupled with WEBrick; it can be used independently.
require 'webrick/cookie'
#
# misc stuff
#
# Set a cookie
cookie = WEBrick::Cookie.new('user_id','12345')
cookie.expires = Time.now + (86400 * 30)
cookie.path = '/'
request.headers_out['Set-Cookie'] = cookie.to_s
# Read cookies
cookies = WEBrick::Cookie.parse(request.headers_in['Cookie'])
It's a very, very short jump from there to a library encapsulating cookie
handling for mod_ruby into something simpler, yet. Extend Apache::Request,
maybe?
cookies = request.cookies
request.cookie = cookie
request.cookie = {:key => 'user_id', :value => @user_id, :path =>
'/', :expires => Time.now + 86400 * 30}
Something like that. I'll write it later today if I get less busy, if nobody
beats me to it.
Kirk Haines