Class Mongrel::CGIWrapper
In: lib/mongrel/cgi.rb
Parent: ::CGI

The beginning of a complete wrapper around Mongrel‘s internal HTTP processing system but maintaining the original Ruby CGI module. Use this only as a crutch to get existing CGI based systems working. It should handle everything, but please notify me if you see special warnings. This work is still very alpha so I need testers to help work out the various corner cases.

The CGIWrapper.handler attribute is normally not set and is available for frameworks that need to get back to the handler. Rails uses this to give people access to the RailsHandler#files (DirHandler really) so they can look-up paths and do other things with the files managed there.

In Rails you can get the real file for a request with:

 path = @request.cgi.handler.files.can_serve(@request['PATH_INFO'])

Which is ugly but does the job. Feel free to write a Rails helper for that. Refer to DirHandler#can_serve for more information on this.

Methods

args   env_table   header   new   out   send_cookies   status   stdinput   stdoutput  

Constants

REMOVED_KEYS = [ "nph","status","server","connection","type", "charset","length","language","expires"]   these are stripped out of any keys passed to CGIWrapper.header function

Attributes

default_really_final  [RW]  Set this to false if you want calls to CGIWrapper.out to not actually send the response until you force it.
handler  [RW] 
options  [R] 

Public Class methods

Takes an HttpRequest and HttpResponse object, plus any additional arguments normally passed to CGI. These are used internally to create a wrapper around the real CGI while maintaining Mongrel‘s view of the world.

Public Instance methods

Used to wrap the normal args variable used inside CGI.

Used to wrap the normal env_table variable used inside CGI.

The header is typically called to send back the header. In our case we collect it into a hash for later usage.

nph — Mostly ignored. It‘ll output the date. connection — Completely ignored. Why is CGI doing this? length — Ignored since Mongrel figures this out from what you write to output.

The dumb thing is people can call header or this or both and in any order. So, we just reuse header and then finalize the HttpResponse the right way. Status is taken from the various options and converted to what Mongrel needs via the CGIWrapper.status function.

We also prevent Rails from actually doing the final send by adding a second parameter "really_final". Only Mongrel calls this after Rails is done. Since this will break other frameworks, it defaults to a different setting for rails (false) and (true) for others.

Takes any ‘cookie’ setting and sends it over the Mongrel header, then removes the setting from the options. If cookie is an Array or Hash then it sends those on with .to_s, otherwise it just calls .to_s on it and hopefully your "cookie" can write itself correctly.

Computes the status once, but lazily so that people who call header twice don‘t get penalized. Because CGI insists on including the options status message in the status we have to do a bit of parsing.

Used to wrap the normal stdinput variable used inside CGI.

The stdoutput should be completely bypassed but we‘ll drop a warning just in case

[Validate]