Parent

Methods

Class Index [+]

Quicksearch

Rack::ShowStatus

Rack::ShowStatus catches all empty responses the app it wraps and replaces them with a site explaining the error.

Additional details can be put into rack.showstatus.detail and will be shown as HTML. If such details exist, the error page is always rendered, even if the reply was not empty.

Public Class Methods

new(app) click to toggle source
    # File lib/rack/showstatus.rb, line 14
14:     def initialize(app)
15:       @app = app
16:       @template = ERB.new(TEMPLATE)
17:     end

Public Instance Methods

call(env) click to toggle source
    # File lib/rack/showstatus.rb, line 19
19:     def call(env)
20:       status, headers, body = @app.call(env)
21:       headers = Utils::HeaderHash.new(headers)
22:       empty = headers['Content-Length'].to_i <= 0
23: 
24:       # client or server error, or explicit message
25:       if (status.to_i >= 400 && empty) || env["rack.showstatus.detail"]
26:         req = Rack::Request.new(env)
27:         message = Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s
28:         detail = env["rack.showstatus.detail"] || message
29:         body = @template.result(binding)
30:         size = Rack::Utils.bytesize(body)
31:         [status, headers.merge("Content-Type" => "text/html", "Content-Length" => size.to_s), [body]]
32:       else
33:         [status, headers, body]
34:       end
35:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.