class Protocol::HTTP::Response

Attributes

body[RW]
headers[RW]
protocol[RW]
status[RW]
version[RW]

Public Class Methods

[](status, headers = nil, body = nil, protocol = nil) click to toggle source
# File lib/protocol/http/response.rb, line 85
def self.[](status, headers = nil, body = nil, protocol = nil)
        body = Body::Buffered.wrap(body)
        headers = ::Protocol::HTTP::Headers[headers]
        
        self.new(nil, status, headers, body, protocol)
end
for_exception(exception) click to toggle source
# File lib/protocol/http/response.rb, line 92
def self.for_exception(exception)
        Response[500, Headers['content-type' => 'text/plain'], ["#{exception.class}: #{exception.message}"]]
end
new(version = nil, status = 200, headers = Headers.new, body = nil, protocol = nil) click to toggle source
# File lib/protocol/http/response.rb, line 31
def initialize(version = nil, status = 200, headers = Headers.new, body = nil, protocol = nil)
        @version = version
        @status = status
        @headers = headers
        @body = body
        @protocol = protocol
end

Public Instance Methods

bad_request?() click to toggle source
# File lib/protocol/http/response.rb, line 77
def bad_request?
        @status == 400
end
continue?() click to toggle source
# File lib/protocol/http/response.rb, line 49
def continue?
        @status == 100
end
failure?() click to toggle source
# File lib/protocol/http/response.rb, line 73
def failure?
        @status and @status >= 400 && @status < 600
end
hijack?() click to toggle source
# File lib/protocol/http/response.rb, line 45
def hijack?
        false
end
not_modified?() click to toggle source
# File lib/protocol/http/response.rb, line 65
def not_modified?
        @status == 304
end
partial?() click to toggle source
# File lib/protocol/http/response.rb, line 57
def partial?
        @status == 206
end
preserve_method?() click to toggle source
# File lib/protocol/http/response.rb, line 69
def preserve_method?
        @status == 307 || @status == 308
end
redirection?() click to toggle source
# File lib/protocol/http/response.rb, line 61
def redirection?
        @status and @status >= 300 && @status < 400
end
server_failure?() click to toggle source
# File lib/protocol/http/response.rb, line 81
def server_failure?
        @status == 500
end
success?() click to toggle source
# File lib/protocol/http/response.rb, line 53
def success?
        @status and @status >= 200 && @status < 300
end
to_ary() click to toggle source
# File lib/protocol/http/response.rb, line 100
def to_ary
        return @status, @headers, @body
end
to_s() click to toggle source
# File lib/protocol/http/response.rb, line 96
def to_s
        "#{@status} #{@version}"
end