Re: mod_ruby Apache::* tutorial

Kirk Haines <[email protected]> Fri, 2 Jun 2006 09:37:04 -0600
Newsgroups gmane.comp.apache.mod-ruby
Message-ID <[email protected]>
On Friday 02 June 2006 8:36 am, Mat Schaffer wrote:
> I'm having a hard time finding tutorial (or documentation other than
> the API in the wiki) for using Apache::request to get access to get/
> post/cookie via eruby/mod_ruby.  The only tutorial I found uses CGI
> from inside eruby, which seems unnecesary.
>
> Is there documentation available?  Or if there's somewhere I could
> get started, I could post my experiences to the wiki in hopes of
> building a tutorial for later users.

Cookies are pretty simple to deal with.

On your outgoing HTTP headers, just create a 'Set-Cookie' header with the 
contents of the cookie for the value.

request.headers_out['Set-Cookie']="user_id=#{@useridx}/#{@confkey}; path=/"

To read cookies, just pull them out of the Cookie header on the incoming http 
headers:

request.headers_in['Cookie'].split(';').each do |cookie|
  k,v = cookie.split(C_equal)
  k.strip!
  v.strip!
  @cookies[k] = v
end

That's the nutshell version of setting and getting cookies.


Kirk Haines