You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.
Class: Seahorse::Client::Http::Response
- Inherits:
-
Object
- Object
- Seahorse::Client::Http::Response
show all
- Defined in:
- aws-sdk-core/lib/seahorse/client/http/response.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Response
Returns a new instance of Response.
9
10
11
12
13
14
15
16
17
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 9
def initialize(options = {})
@status_code = options[:status_code] || 0
@headers = options[:headers] || Headers.new
@body = options[:body] || StringIO.new
@listeners = Hash.new { |h,k| h[k] = [] }
@complete = false
@done = nil
@error = nil
end
|
Instance Attribute Details
#error ⇒ StandardError?
27
28
29
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 27
def error
@error
end
|
24
25
26
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 24
def
@headers
end
|
#status_code ⇒ Integer
Returns 0
if the request failed to generate
any response.
21
22
23
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 21
def status_code
@status_code
end
|
Instance Method Details
#body ⇒ IO
30
31
32
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 30
def body
@body
end
|
#body=(io) ⇒ Object
35
36
37
38
39
40
41
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 35
def body=(io)
@body = case io
when nil then StringIO.new('')
when String then StringIO.new(io)
else io
end
end
|
#body_contents ⇒ String
44
45
46
47
48
49
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 44
def body_contents
body.rewind
contents = body.read
body.rewind
contents
end
|
#on_data(&callback) ⇒ Object
123
124
125
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 123
def on_data(&callback)
@listeners[:data] << callback
end
|
#on_done(status_code_range = nil, &callback) ⇒ Object
127
128
129
130
131
132
133
134
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 127
def on_done(status_code_range = nil, &callback)
listener = listener(status_code_range, callback)
if @done
listener.call
else
@listeners[:done] << listener
end
end
|
#on_error(&callback) ⇒ Object
144
145
146
147
148
149
150
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 144
def on_error(&callback)
on_done(0..599) do
if @error
yield(@error)
end
end
end
|
119
120
121
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 119
def (status_code_range = nil, &block)
@listeners[:headers] << listener(status_code_range, block)
end
|
#on_success(status_code_range = 200..599, &callback) ⇒ Object
136
137
138
139
140
141
142
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 136
def on_success(status_code_range = 200..599, &callback)
on_done(status_code_range) do
unless @error
yield
end
end
end
|
#reset ⇒ Object
152
153
154
155
156
157
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 152
def reset
@status_code = 0
@headers.clear
@body.truncate(0)
@error = nil
end
|
#signal_data(chunk) ⇒ Object
60
61
62
63
64
65
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 60
def signal_data(chunk)
unless chunk == ''
@body.write(chunk)
emit(:data, chunk)
end
end
|
#signal_done ⇒ Object
#signal_done(options = {}) ⇒ Object
Completes the http response.
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 97
def signal_done(options = {})
if options.keys.sort == [:body, :headers, :status_code]
(options[:status_code], options[:headers])
signal_data(options[:body])
signal_done
elsif options.empty?
@body.rewind if @body.respond_to?(:rewind)
@done = true
emit(:done)
else
msg = "options must be empty or must contain :status_code, :headers, "
msg << "and :body"
raise ArgumentError, msg
end
end
|
#signal_error(networking_error) ⇒ Object
114
115
116
117
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 114
def signal_error(networking_error)
@error = networking_error
signal_done
end
|
53
54
55
56
57
|
# File 'aws-sdk-core/lib/seahorse/client/http/response.rb', line 53
def (status_code, )
@status_code = status_code
@headers = Headers.new()
emit(:headers, @status_code, @headers)
end
|