From: Brian Candler Date: 2003-03-18T21:42:05+09:00 Subject: Re: Parsing a CGI query (Re: Your favorite Ruby web library?) On Tue, Mar 18, 2003 at 02:22:47PM +0900, Justin White wrote: > On Sunday, March 16, 2003, at 07:08 , Eric Hodel wrote: > > > Provided you can run a CGI, Borges should work. If you're not using > > mod_ruby, you'll have to figure out how to grab the GET and POST args > > yourself, because I've not puzzled that out yet. > > i have. i'll put it down here, for you and to make sure i actually know > what i'm doing (check my sanity fellow Rubyists :P ) > > CGI data is stored in environment variables passed to the CGI > executable. use Ruby's global ENV Hash to retrieve them. > ENV['REQUEST_METHOD'] is GET or POST. for GET requests, > ENV['QUERY_STRING'] is the string after the question mark in the URL. > for example: cgi.rb?key=val;foo=bar > QUERY_STRING = 'key=val;foo=bar' > > split QUERY_STRING on ';' or '&'. But then you are rewriting the CGI module from scratch...! You can instead just subclass CGI and provide it with methods to fetch the environment (envtable) and POST data (stdinput), and it will do all the work for you. See ahoward's MOD_FCGI code for an example of how to do this: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/64468 Regards, Brian.