Skip to content

Commit

Permalink
add streaming response support
Browse files Browse the repository at this point in the history
  • Loading branch information
korbin committed Aug 12, 2024
1 parent c1ff0ae commit c47d7ea
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/async/http/faraday/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,23 @@ def call(env)
request = ::Protocol::HTTP::Request.new(endpoint.scheme, endpoint.authority, method, endpoint.path, nil, headers, body)

with_timeout do
response = client.call(request)

save_response(env, response.status, encoded_body(response), response.headers)
if env.stream_response?
response = env.stream_response do |&on_data|
response = client.call(request)

response.each do |chunk|
on_data.call(chunk)
end

response
end

save_response(env, response.status, nil, response.headers)
else
response = client.call(request)

save_response(env, response.status, encoded_body(response), response.headers)
end
end
end

Expand Down

0 comments on commit c47d7ea

Please sign in to comment.