Skip to content

Commit

Permalink
try middleware chunked again
Browse files Browse the repository at this point in the history
  • Loading branch information
ndushay committed Sep 11, 2019
1 parent ffb3c70 commit d090356
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions app/models/symphony_reader.rb
Expand Up @@ -9,11 +9,11 @@ class ResponseError < StandardError; end
attr_reader :catkey

def self.client
Faraday.new(headers: Settings.catalog.symphony.headers) # do |conn|
# conn.request :url_encoded
# conn.use FaradayMiddleware::Chunked
# conn.adapter :net_http
# end
Faraday.new(headers: Settings.catalog.symphony.headers) do |conn|
conn.request :url_encoded
conn.response :chunked
conn.adapter :net_http
end
end

def initialize(catkey:)
Expand Down Expand Up @@ -49,21 +49,21 @@ def client
def symphony_response
resp = client.get(format(Settings.catalog.symphony.json_url, catkey: catkey))

if resp.headers['transfer-encoding'] == 'chunked'
streamed = []

client.get(format(Settings.catalog.symphony.json_url, catkey: catkey)) do |req|
# Set a callback which will receive tuples of chunk Strings
# and the sum of characters received so far
req.options.on_data = Proc.new do |chunk, overall_received_bytes|
puts "Received #{overall_received_bytes} characters"
streamed << chunk
end
end

resp.body = streamed.join
resp.status = 200
end
# if resp.headers['transfer-encoding'] == 'chunked'
# streamed = []
#
# client.get(format(Settings.catalog.symphony.json_url, catkey: catkey)) do |req|
# # Set a callback which will receive tuples of chunk Strings
# # and the sum of characters received so far
# req.options.on_data = Proc.new do |chunk, overall_received_bytes|
# puts "Received #{overall_received_bytes} characters"
# streamed << chunk
# end
# end
#
# resp.body = streamed.join
# resp.status = 200
# end

if resp.status == 200
validate_response(resp)
Expand Down

0 comments on commit d090356

Please sign in to comment.