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

Inherits:
CGI
  • Object
show all
Defined in:
lib/rack/adapter/rails.rb

Instance Method Summary collapse

Constructor Details

#initialize(request, response, *args) ⇒ CGIWrapper

Returns a new instance of CGIWrapper.



80
81
82
83
84
85
86
87
# File 'lib/rack/adapter/rails.rb', line 80

def initialize(request, response, *args)
  @request  = request
  @response = response
  @args     = *args
  @input    = request.body

  super *args
end

Instance Method Details

#argsObject

Used to wrap the normal args variable used inside CGI.



140
141
142
# File 'lib/rack/adapter/rails.rb', line 140

def args
  @args
end

#cookiesObject



131
132
133
# File 'lib/rack/adapter/rails.rb', line 131

def cookies
  @request.cookies
end

#env_tableObject

Used to wrap the normal env_table variable used inside CGI.



145
146
147
# File 'lib/rack/adapter/rails.rb', line 145

def env_table
  @request.env
end

#header(options = "text/html") ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rack/adapter/rails.rb', line 89

def header(options = "text/html")
  if options.is_a?(String)
    @response['Content-Type']     = options unless @response['Content-Type']
  else
    @response['Content-Length']   = options.delete('Content-Length').to_s if options['Content-Length']
  
    @response['Content-Type']     = options.delete('type') || "text/html"
    @response['Content-Type']    += "; charset=" + options.delete('charset') if options['charset']
              
    @response['Content-Language'] = options.delete('language') if options['language']
    @response['Expires']          = options.delete('expires') if options['expires']

    @response.status              = options.delete('Status') if options['Status']
    
    # Convert 'cookie' header to 'Set-Cookie' headers.
    # Because Set-Cookie header can appear more the once in the response body, 
    # we store it in a line break seperated string that will be translated to
    # multiple Set-Cookie header by the handler.
    if cookie = options.delete('cookie')
      cookies = []
      
      case cookie
        when Array then cookie.each { |c| cookies << c.to_s }
        when Hash  then cookie.each { |_, c| cookies << c.to_s }
        else            cookies << cookie.to_s
      end
        
      @output_cookies.each { |c| cookies << c.to_s } if @output_cookies
      
      @response['Set-Cookie'] = [@response['Set-Cookie'], cookies].compact.join("\n")
    end
    
    options.each { |k,v| @response[k] = v }
  end
  
  ""
end

#paramsObject



127
128
129
# File 'lib/rack/adapter/rails.rb', line 127

def params
  @params ||= @request.params
end

#query_stringObject



135
136
137
# File 'lib/rack/adapter/rails.rb', line 135

def query_string
  @request.query_string
end

#stdinputObject

Used to wrap the normal stdinput variable used inside CGI.



150
151
152
# File 'lib/rack/adapter/rails.rb', line 150

def stdinput
  @input
end

#stdoutputObject



154
155
156
157
# File 'lib/rack/adapter/rails.rb', line 154

def stdoutput
  STDERR.puts "stdoutput should not be used."
  @response.body
end