Skip to content

Commit

Permalink
Excon streaming (#1026)
Browse files Browse the repository at this point in the history
* implement excon streaming

* trust that excon will return empty body on streamed responses

* track total byte size ourselves

* the extra args are needed
  • Loading branch information
technoweenie authored Sep 22, 2019
1 parent 80ba52c commit 872a249
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/faraday/adapter/excon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ def call(env)
opts = opts_from_env(env)
conn = create_connection(env, opts)

resp = conn.request(method: env[:method].to_s.upcase,
headers: env[:request_headers],
body: read_body(env))
req_opts = {
method: env[:method].to_s.upcase,
headers: env[:request_headers],
body: read_body(env)
}

req = env[:request]
if req&.stream_response?
warn "Streaming downloads for #{self.class.name} are not yet " \
' implemented.'
req.on_data.call(resp.body, resp.body.bytesize)
total = 0
req_opts[:response_block] = lambda do |chunk, _remain, _total|
req.on_data.call(chunk, total += chunk.size)
end
end

resp = conn.request(req_opts)
save_response(env, resp.status.to_i, resp.body, resp.headers,
resp.reason_phrase)

Expand Down

0 comments on commit 872a249

Please sign in to comment.