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.
14
15
16
17
18
19
20
|
# File 'lib/protocol/http/response.rb', line 14
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.
25
26
27
|
# File 'lib/protocol/http/response.rb', line 25
def body
@body
end
|
Returns the value of attribute headers.
24
25
26
|
# File 'lib/protocol/http/response.rb', line 24
def
@headers
end
|
#protocol ⇒ Object
Returns the value of attribute protocol.
26
27
28
|
# File 'lib/protocol/http/response.rb', line 26
def protocol
@protocol
end
|
#status ⇒ Object
Returns the value of attribute status.
23
24
25
|
# File 'lib/protocol/http/response.rb', line 23
def status
@status
end
|
#version ⇒ Object
Returns the value of attribute version.
22
23
24
|
# File 'lib/protocol/http/response.rb', line 22
def version
@version
end
|
Class Method Details
.[](status, headers = nil, body = nil, protocol = nil) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/protocol/http/response.rb', line 75
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
82
83
84
|
# File 'lib/protocol/http/response.rb', line 82
def self.for_exception(exception)
Response[500, Headers['content-type' => 'text/plain'], ["#{exception.class}: #{exception.message}"]]
end
|
Instance Method Details
#bad_request? ⇒ Boolean
64
65
66
|
# File 'lib/protocol/http/response.rb', line 64
def bad_request?
@status == 400
end
|
#continue? ⇒ Boolean
32
33
34
|
# File 'lib/protocol/http/response.rb', line 32
def continue?
@status == 100
end
|
#failure? ⇒ Boolean
60
61
62
|
# File 'lib/protocol/http/response.rb', line 60
def failure?
@status and @status >= 400 && @status < 600
end
|
#hijack? ⇒ Boolean
28
29
30
|
# File 'lib/protocol/http/response.rb', line 28
def hijack?
false
end
|
#internal_server_error? ⇒ Boolean
Also known as:
server_failure?
68
69
70
|
# File 'lib/protocol/http/response.rb', line 68
def internal_server_error?
@status == 500
end
|
#not_modified? ⇒ Boolean
52
53
54
|
# File 'lib/protocol/http/response.rb', line 52
def not_modified?
@status == 304
end
|
#ok? ⇒ Boolean
36
37
38
|
# File 'lib/protocol/http/response.rb', line 36
def ok?
@status == 200
end
|
#partial? ⇒ Boolean
44
45
46
|
# File 'lib/protocol/http/response.rb', line 44
def partial?
@status == 206
end
|
#preserve_method? ⇒ Boolean
56
57
58
|
# File 'lib/protocol/http/response.rb', line 56
def preserve_method?
@status == 307 || @status == 308
end
|
#redirection? ⇒ Boolean
48
49
50
|
# File 'lib/protocol/http/response.rb', line 48
def redirection?
@status and @status >= 300 && @status < 400
end
|
#success? ⇒ Boolean
40
41
42
|
# File 'lib/protocol/http/response.rb', line 40
def success?
@status and @status >= 200 && @status < 300
end
|
#to_ary ⇒ Object
90
91
92
|
# File 'lib/protocol/http/response.rb', line 90
def to_ary
return @status, @headers, @body
end
|
#to_s ⇒ Object
86
87
88
|
# File 'lib/protocol/http/response.rb', line 86
def to_s
"#{@status} #{@version}"
end
|