From: anders@... (Anders Johannsen) Date: 2001-09-18T22:22:30+09:00 Subject: [ruby-talk:21315] Suggestions for new CGI lib From the comp.lang.ruby thread "Minor cgi.rb question" (2001-09-03), I gathered that some people disagree with the way the current 'cgi.rb' is designed. Incidently, the lack of consistensy in 'cgi.rb' has been my primary reason for _not_ using Ruby as a web scripting language. Based on my experience in web scripting, I have developed a working model for 'next generation' CGI, which may or may not be what we are looking for. Since it is a model, actual functionality is yet to be implemented. I would appreciate a discussion of pros and cons in my suggestion. Comments and improvements are most welcome. The goals of design are to: * Introduce the well-known 'Request/Response' model * Separate Cookie, Post, Get and Environment namespaces * Add support for 'plug-in' output handlers, thus making for example gz compression of output easy. * Use an open model to make integration with fastcgi/cgisock and future technologies seamless * Separate actual CGI and HTML generation, as they are two very different matters (my suggestion only cover CGI) -- while still maintaining 'ease-of-use' The design is basically comprised by the following base classes, all accessed through the instanciated CGI class (as indicated in the comments) CGI # cgi CGI::Request # cgi.request CGI::Request::Cookie # cgi.request.cookie CGI::Request::Post # cgi.request.post CGI::Request::Get # cgi.request.get CGI::Request::Env # cgi.request.env CGI::Request::Header # cgi.request.header CGI::Request::Var # cgi.request.var CGI::Response # cgi.response CGI::Response::Cookie # cgi.response.cookie CGI::Response::Header # cgi.response.header CGI::Namespace # cgi.namespace CGI::Output # cgi.output CGI::Session # cgi.session A practical example of usage could be: CGI.new do |cgi| req = cgi.request req.cookie['user_var'] # Get the named cookie 'user_var' req.header['X-Something'] # Get the named header 'X-Something' req.var['user_var'] # Get the named variable 'user_var'. Cookie, Post, Get, Env and Headers are merged in a configurable order # Add text to the output buffer cgi << " TEST " # Set a custom cookie and header in the response cgi.response.cookie.set ("name", "content") cgi.response.header.set ("name", "content") # Set output options cgi.output.handler = call_back cgi.output.stream = $stdout # Introduce new namespace with the indicated variables exported (non-existant variables is nil) cgi.namespace.var do unless non_existant_var.nil? # Do stuff end end end # At the end of the block, cgi.print is automatically called Let me know you think. Best regards, Anders Johannsen Denmark