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 88
88:           def initialize(request, response, *args)
89:             @request  = request
90:             @response = response
91:             @args     = *args
92:             @input    = request.body
93: 
94:             super *args
95:           end

Public Instance args()

Used to wrap the normal args variable used inside CGI.

     # File lib/rack/adapter/rails.rb, line 154
154:           def args
155:             @args
156:           end

Public Instance cookies()

     # File lib/rack/adapter/rails.rb, line 145
145:           def cookies
146:             @request.cookies
147:           end

Public Instance env_table()

Used to wrap the normal env_table variable used inside CGI.

     # File lib/rack/adapter/rails.rb, line 159
159:           def env_table
160:             @request.env
161:           end

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

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

Public Instance params()

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

Public Instance query_string()

     # File lib/rack/adapter/rails.rb, line 149
149:           def query_string
150:             @request.query_string
151:           end

Public Instance stdinput()

Used to wrap the normal stdinput variable used inside CGI.

     # File lib/rack/adapter/rails.rb, line 164
164:           def stdinput
165:             @input
166:           end

Public Instance stdoutput()

     # File lib/rack/adapter/rails.rb, line 168
168:           def stdoutput
169:             STDERR.puts "stdoutput should not be used."
170:             @response.body
171:           end