class FTW::Response
An HTTP Response
.
See RFC2616 section 6: <tools.ietf.org/html/rfc2616#section-6>
Constants
- STATUS_REASON_MAP
Translated from the recommendations listed in RFC2616 section 6.1.1 See RFC2616 section 6.1.1: <tools.ietf.org/html/rfc2616#section-6.1.1>
Attributes
reason[R]
The reason phrase (RFC2616 6.1.1) See RFC2616 section 6.1.1: <tools.ietf.org/html/rfc2616#section-6.1.1>
status[R]
The http status code (RFC2616 6.1.1) See RFC2616 section 6.1.1: <tools.ietf.org/html/rfc2616#section-6.1.1>
Public Class Methods
new()
click to toggle source
Create a new Response
.
Calls superclass method
FTW::HTTP::Message::new
# File lib/ftw/response.rb, line 53 def initialize super @logger = Cabin::Channel.get @reason = "" # Empty reason string by default. It is not required. end
Public Instance Methods
error?()
click to toggle source
Is this response an error?
# File lib/ftw/response.rb, line 66 def error? # 4xx and 5xx are errors return @status >= 400 && @status < 600 end
redirect?()
click to toggle source
Is this response a redirect?
# File lib/ftw/response.rb, line 60 def redirect? # redirects are 3xx return @status >= 300 && @status < 400 end
status=(code)
click to toggle source
Set the status code
# File lib/ftw/response.rb, line 72 def status=(code) code = code.to_i if !code.is_a?(Fixnum) # TODO(sissel): Validate that 'code' is a 3 digit number @status = code # Attempt to set the reason if the status code has a known reason # recommendation. If one is not found, default to the current reason. @reason = STATUS_REASON_MAP.fetch(@status, @reason) end
status_line()
click to toggle source
Get the status-line string, like “HTTP/1.0 200 OK”
# File lib/ftw/response.rb, line 83 def status_line # First line is 'Status-Line' from RFC2616 section 6.1 # Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF # etc... return "HTTP/#{version} #{status} #{reason}" end
Also aliased as: start_line
upgrade?()
click to toggle source
Is this Response
the result of a successful Upgrade request?
# File lib/ftw/response.rb, line 94 def upgrade? return false unless status == 101 # "Switching Protocols" return false unless headers["Connection"] == "Upgrade" return true end