9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/common/client/concerns/streaming_client.rb', line 9
def streaming_get(uri, , , yielder)
request = Net::HTTP::Get.new(uri)
.each { |k, v| request[k] = v }
begin
Net::HTTP.start(uri.host, uri.port, read_timeout: 20, use_ssl: (uri.scheme == 'https')) do |http|
http.request request do |response|
if response.is_a?(Net::HTTPClientError) || response.is_a?(Net::HTTPServerError)
raise Common::Client::Errors::ClientError, "Streaming request failed: #{response.code}"
end
.call response.canonical_each
response.read_body do |chunk|
yielder << chunk
end
end
end
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
raise Common::Client::Errors::ClientError, "Streaming request failed: #{e.message}"
end
end
|