Class: JRuby::Rack::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/jruby/rack/grizzly_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_server) ⇒ Errors

Returns a new instance of Errors.



175
176
177
# File 'lib/jruby/rack/grizzly_helper.rb', line 175

def initialize(file_server)
  @file_server = file_server
end

Instance Method Details

#call(env) ⇒ Object



179
180
181
# File 'lib/jruby/rack/grizzly_helper.rb', line 179

def call(env)
  [code = response_code(env), *response_content(env, code)]
end

#response_code(env) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/jruby/rack/grizzly_helper.rb', line 183

def response_code(env)
  exc = env['rack.exception']
  if exc
    env['rack.showstatus.detail'] = exc.getMessage
    if exc.getCause.kind_of?(Java::JavaLang::InterruptedException)
      503
    else
      500
    end
  else
    500
  end
end

#response_content(env, code) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/jruby/rack/grizzly_helper.rb', line 197

def response_content(env, code)
  @responses ||= Hash.new do |h,k|
    env["PATH_INFO"] = "/#{code}.html"
    response = @file_server.call(env)
    body = response[2]
    unless Array === body
      newbody = ""
      body.each do |chunk|
        newbody << chunk
      end
      response[2] = [newbody]
    end
    h[k] = response
  end
  response = @responses[code]
  if response[0] != 404
    env["rack.showstatus.detail"] = nil
    response[1..2]
  else
    [{}, []]
  end
end