Class: Protocol::HTTP::Response
- Inherits:
-
Object
- Object
- Protocol::HTTP::Response
show all
- Includes:
- Body::Reader
- Defined in:
- lib/protocol/http/response.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#body?, #close, #each, #finish, #read, #save
Constructor Details
#initialize(version = nil, status = 200, headers = Headers.new, body = nil, protocol = nil) ⇒ Response
Returns a new instance of Response.
31
32
33
34
35
36
37
|
# File 'lib/protocol/http/response.rb', line 31
def initialize(version = nil, status = 200, = Headers.new, body = nil, protocol = nil)
@version = version
@status = status
@headers =
@body = body
@protocol = protocol
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
42
43
44
|
# File 'lib/protocol/http/response.rb', line 42
def body
@body
end
|
Returns the value of attribute headers.
41
42
43
|
# File 'lib/protocol/http/response.rb', line 41
def
@headers
end
|
#protocol ⇒ Object
Returns the value of attribute protocol.
43
44
45
|
# File 'lib/protocol/http/response.rb', line 43
def protocol
@protocol
end
|
#status ⇒ Object
Returns the value of attribute status.
40
41
42
|
# File 'lib/protocol/http/response.rb', line 40
def status
@status
end
|
#version ⇒ Object
Returns the value of attribute version.
39
40
41
|
# File 'lib/protocol/http/response.rb', line 39
def version
@version
end
|
Class Method Details
.[](status, headers = nil, body = nil, protocol = nil) ⇒ Object
85
86
87
88
89
90
|
# File 'lib/protocol/http/response.rb', line 85
def self.[](status, = nil, body = nil, protocol = nil)
body = Body::Buffered.wrap(body)
= ::Protocol::HTTP::Headers[]
self.new(nil, status, , body, protocol)
end
|
.for_exception(exception) ⇒ Object
92
93
94
|
# 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
|
Instance Method Details
#bad_request? ⇒ Boolean
77
78
79
|
# File 'lib/protocol/http/response.rb', line 77
def bad_request?
@status == 400
end
|
#continue? ⇒ Boolean
49
50
51
|
# File 'lib/protocol/http/response.rb', line 49
def continue?
@status == 100
end
|
#failure? ⇒ Boolean
73
74
75
|
# File 'lib/protocol/http/response.rb', line 73
def failure?
@status and @status >= 400 && @status < 600
end
|
#hijack? ⇒ Boolean
45
46
47
|
# File 'lib/protocol/http/response.rb', line 45
def hijack?
false
end
|
#not_modified? ⇒ Boolean
65
66
67
|
# File 'lib/protocol/http/response.rb', line 65
def not_modified?
@status == 304
end
|
#partial? ⇒ Boolean
57
58
59
|
# File 'lib/protocol/http/response.rb', line 57
def partial?
@status == 206
end
|
#preserve_method? ⇒ Boolean
69
70
71
|
# File 'lib/protocol/http/response.rb', line 69
def preserve_method?
@status == 307 || @status == 308
end
|
#redirection? ⇒ Boolean
61
62
63
|
# File 'lib/protocol/http/response.rb', line 61
def redirection?
@status and @status >= 300 && @status < 400
end
|
#server_failure? ⇒ Boolean
81
82
83
|
# File 'lib/protocol/http/response.rb', line 81
def server_failure?
@status == 500
end
|
#success? ⇒ Boolean
53
54
55
|
# File 'lib/protocol/http/response.rb', line 53
def success?
@status and @status >= 200 && @status < 300
end
|
#to_ary ⇒ Object
100
101
102
|
# File 'lib/protocol/http/response.rb', line 100
def to_ary
return @status, @headers, @body
end
|
#to_s ⇒ Object
96
97
98
|
# File 'lib/protocol/http/response.rb', line 96
def to_s
"#{@status} #{@version}"
end
|