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, reason = nil, headers = [], body = nil, protocol = nil) ⇒ Response
Returns a new instance of Response.
29
30
31
32
33
34
35
36
|
# File 'lib/protocol/http/response.rb', line 29
def initialize(version = nil, status = 200, reason = nil, = [], body = nil, protocol = nil)
@version = version
@status = status
@reason = reason
@headers =
@body = body
@protocol = protocol
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
41
42
43
|
# File 'lib/protocol/http/response.rb', line 41
def body
@body
end
|
Returns the value of attribute headers.
40
41
42
|
# File 'lib/protocol/http/response.rb', line 40
def
@headers
end
|
#protocol ⇒ Object
Returns the value of attribute protocol.
42
43
44
|
# File 'lib/protocol/http/response.rb', line 42
def protocol
@protocol
end
|
#status ⇒ Object
Returns the value of attribute status.
39
40
41
|
# File 'lib/protocol/http/response.rb', line 39
def status
@status
end
|
#version ⇒ Object
Returns the value of attribute version.
38
39
40
|
# File 'lib/protocol/http/response.rb', line 38
def version
@version
end
|
Class Method Details
.[](status, headers = [], body = nil, protocol = nil) ⇒ Object
80
81
82
83
84
|
# File 'lib/protocol/http/response.rb', line 80
def self.[](status, = [], body = nil, protocol = nil)
body = Body::Buffered.wrap(body)
self.new(nil, status, nil, , body, protocol)
end
|
.for_exception(exception) ⇒ Object
86
87
88
|
# File 'lib/protocol/http/response.rb', line 86
def self.for_exception(exception)
Response[500, Headers['content-type' => 'text/plain'], ["#{exception.class}: #{exception.message}"]]
end
|
Instance Method Details
#bad_request? ⇒ Boolean
72
73
74
|
# File 'lib/protocol/http/response.rb', line 72
def bad_request?
status == 400
end
|
#continue? ⇒ Boolean
48
49
50
|
# File 'lib/protocol/http/response.rb', line 48
def continue?
status == 100
end
|
#failure? ⇒ Boolean
68
69
70
|
# File 'lib/protocol/http/response.rb', line 68
def failure?
status >= 400 && status < 600
end
|
#hijack? ⇒ Boolean
44
45
46
|
# File 'lib/protocol/http/response.rb', line 44
def hijack?
false
end
|
#partial? ⇒ Boolean
56
57
58
|
# File 'lib/protocol/http/response.rb', line 56
def partial?
status == 206
end
|
#preserve_method? ⇒ Boolean
64
65
66
|
# File 'lib/protocol/http/response.rb', line 64
def preserve_method?
status == 307 || status == 308
end
|
#redirection? ⇒ Boolean
60
61
62
|
# File 'lib/protocol/http/response.rb', line 60
def redirection?
status >= 300 && status < 400
end
|
#server_failure? ⇒ Boolean
76
77
78
|
# File 'lib/protocol/http/response.rb', line 76
def server_failure?
status == 500
end
|
#success? ⇒ Boolean
52
53
54
|
# File 'lib/protocol/http/response.rb', line 52
def success?
status >= 200 && status < 300
end
|
#to_ary ⇒ Object
94
95
96
|
# File 'lib/protocol/http/response.rb', line 94
def to_ary
return @status, @headers, @body
end
|
#to_s ⇒ Object
90
91
92
|
# File 'lib/protocol/http/response.rb', line 90
def to_s
"#{@status} #{@reason} #{@version}"
end
|