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.
REMOVED_KEYS | = | [ "nph","status","server","connection","type", "charset","length","language","expires"] | these are stripped out of any keys passed to CGIWrapper.header function |
handler | [W] | |
handler | [R] | |
options | [R] |
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.
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.
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.