Class: Async::HTTP::Response
- Inherits:
-
Object
- Object
- Async::HTTP::Response
show all
- Includes:
- Body::Reader
- Defined in:
- lib/async/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) ⇒ Response
Returns a new instance of Response.
29
30
31
32
33
34
35
|
# File 'lib/async/http/response.rb', line 29
def initialize(version = nil, status = 200, reason = nil, = [], body = nil)
@version = version
@status = status
@reason = reason
@headers =
@body = body
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
41
42
43
|
# File 'lib/async/http/response.rb', line 41
def body
@body
end
|
Returns the value of attribute headers.
40
41
42
|
# File 'lib/async/http/response.rb', line 40
def
@headers
end
|
#reason ⇒ Object
Returns the value of attribute reason.
39
40
41
|
# File 'lib/async/http/response.rb', line 39
def reason
@reason
end
|
#status ⇒ Object
Returns the value of attribute status.
38
39
40
|
# File 'lib/async/http/response.rb', line 38
def status
@status
end
|
#version ⇒ Object
Returns the value of attribute version.
37
38
39
|
# File 'lib/async/http/response.rb', line 37
def version
@version
end
|
Class Method Details
.[](status, headers = [], body = nil) ⇒ Object
75
76
77
78
79
|
# File 'lib/async/http/response.rb', line 75
def self.[](status, = [], body = nil)
body = Body::Buffered.wrap(body)
self.new(nil, status, nil, , body)
end
|
.for_exception(exception) ⇒ Object
81
82
83
|
# File 'lib/async/http/response.rb', line 81
def self.for_exception(exception)
Async::HTTP::Response[500, {'content-type' => 'text/plain'}, ["#{exception.class}: #{exception.message}"]]
end
|
Instance Method Details
#bad_request? ⇒ Boolean
67
68
69
|
# File 'lib/async/http/response.rb', line 67
def bad_request?
status == 400
end
|
#continue? ⇒ Boolean
43
44
45
|
# File 'lib/async/http/response.rb', line 43
def continue?
status == 100
end
|
#failure? ⇒ Boolean
63
64
65
|
# File 'lib/async/http/response.rb', line 63
def failure?
status >= 400 && status < 600
end
|
#partial? ⇒ Boolean
51
52
53
|
# File 'lib/async/http/response.rb', line 51
def partial?
status == 206
end
|
#preserve_method? ⇒ Boolean
59
60
61
|
# File 'lib/async/http/response.rb', line 59
def preserve_method?
status == 307 || status == 308
end
|
#redirection? ⇒ Boolean
55
56
57
|
# File 'lib/async/http/response.rb', line 55
def redirection?
status >= 300 && status < 400
end
|
#server_failure? ⇒ Boolean
71
72
73
|
# File 'lib/async/http/response.rb', line 71
def server_failure?
status == 500
end
|
#success? ⇒ Boolean
47
48
49
|
# File 'lib/async/http/response.rb', line 47
def success?
status >= 200 && status < 300
end
|
#to_s ⇒ Object
85
86
87
|
# File 'lib/async/http/response.rb', line 85
def to_s
"#{@status} #{@reason} #{@version}"
end
|