class Rackful::StatusCodes::HTTPStatus

Exception which represents an HTTP Status response. @abstract

Attributes

headers[R]
status[R]
to_rackful[R]

Public Class Methods

new(status, message = nil, info = {}) click to toggle source

@param status [Symbol, Integer] e.g. ‘404` or `:not_found` @param message [String] XHTML @param info [ { Symbol => Object, String => String } ]

*   **Objects** indexed by **Symbols** are returned in the response body.
*   **Strings** indexed by **Strings** are returned as response headers.
Calls superclass method
# File lib/rackful/httpstatus.rb, line 56
def initialize status, message = nil, info = {}
  @status = Rack::Utils.status_code status
  raise "Wrong status: #{status}" if 0 === @status
  message ||= ''
  @headers = {}
  @to_rackful = {}
  info.each do
    |k, v|
    if k.kind_of? Symbol
      @to_rackful[k] = v
    else
      @headers[k] = v.to_s
    end
  end
  @to_rackful = nil if @to_rackful.empty?
  if message
    message = message.to_s
    begin
      Nokogiri.XML(
        '<?xml version="1.0" encoding="UTF-8" ?>' +
        "<div>#{message}</div>"
      ) do |config| config.strict.nonet end
    rescue
      message = Rack::Utils.escape_html(message)
    end
  end
  super message
end

Public Instance Methods

title() click to toggle source

@api private

# File lib/rackful/httpstatus.rb, line 87
def title
  "#{status} #{Rack::Utils::HTTP_STATUS_CODES[status]}"
end