Class: Rack::Adapter::Rails::CGIWrapper

Class Rack::Adapter::Rails::CGIWrapper < ::CGI

(in files lib/rack/adapter/rails.rb )

Adapter to run a Rails app with any supported Rack handler. By default it will try to load the Rails application in the current directory in the development environment.

Options:

 root: Root directory of the Rails app
 environment: Rails environment to run in (development [default], production or test)
 prefix: Set the relative URL root.

Based on fuzed.rubyforge.org/ Rails adapter

Methods

Public Class new(request, response, *args)

    # File lib/rack/adapter/rails.rb, line 80
80:           def initialize(request, response, *args)
81:             @request  = request
82:             @response = response
83:             @args     = *args
84:             @input    = request.body
85: 
86:             super *args
87:           end

Public Instance args()

Used to wrap the normal args variable used inside CGI.

     # File lib/rack/adapter/rails.rb, line 146
146:           def args
147:             @args
148:           end

Public Instance cookies()

     # File lib/rack/adapter/rails.rb, line 137
137:           def cookies
138:             @request.cookies
139:           end

Public Instance env_table()

Used to wrap the normal env_table variable used inside CGI.

     # File lib/rack/adapter/rails.rb, line 151
151:           def env_table
152:             @request.env
153:           end

Public Instance header(options = "text/html")

     # File lib/rack/adapter/rails.rb, line 89
 89:           def header(options = "text/html")
 90:             if options.is_a?(String)
 91:               @response['Content-Type']     = options unless @response['Content-Type']
 92:             else
 93:               @response['Content-Length']   = options.delete('Content-Length').to_s if options['Content-Length']
 94:             
 95:               @response['Content-Type']     = options.delete('type') || "text/html"
 96:               @response['Content-Type']    += "; charset=" + options.delete('charset') if options['charset']
 97:                         
 98:               @response['Content-Language'] = options.delete('language') if options['language']
 99:               @response['Expires']          = options.delete('expires') if options['expires']
100: 
101:               @response.status              = options.delete('Status') if options['Status']
102:               
103:               # Convert 'cookie' header to 'Set-Cookie' headers.
104:               # Because Set-Cookie header can appear more the once in the response body, 
105:               # we store it in a line break seperated string that will be translated to
106:               # multiple Set-Cookie header by the handler.
107:               if cookie = options.delete('cookie')
108:                 cookies = []
109:                 
110:                 case cookie
111:                   when Array then cookie.each { |c| cookies << c.to_s }
112:                   when Hash  then cookie.each { |_, c| cookies << c.to_s }
113:                   else            cookies << cookie.to_s
114:                 end
115:                 
116:                 @output_cookies.each { |c| cookies << c.to_s } if @output_cookies
117:                 
118:                 @response['Set-Cookie'] = [@response['Set-Cookie'], cookies].compact
119:                 # See http://groups.google.com/group/rack-devel/browse_thread/thread/e8759b91a82c5a10/a8dbd4574fe97d69?#a8dbd4574fe97d69
120:                 if Thin.ruby_18?
121:                   @response['Set-Cookie'].flatten!
122:                 else
123:                   @response['Set-Cookie'] = @response['Set-Cookie'].join("\n")
124:                 end
125:               end
126:               
127:               options.each { |k,v| @response[k] = v }
128:             end
129:             
130:             ""
131:           end

Public Instance params()

     # File lib/rack/adapter/rails.rb, line 133
133:           def params
134:             @params ||= @request.params
135:           end

Public Instance query_string()

     # File lib/rack/adapter/rails.rb, line 141
141:           def query_string
142:             @request.query_string
143:           end

Public Instance stdinput()

Used to wrap the normal stdinput variable used inside CGI.

     # File lib/rack/adapter/rails.rb, line 156
156:           def stdinput
157:             @input
158:           end

Public Instance stdoutput()

     # File lib/rack/adapter/rails.rb, line 160
160:           def stdoutput
161:             STDERR.puts "stdoutput should not be used."
162:             @response.body
163:           end