Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/async/http/faraday/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,19 @@ def perform_request(env)
response = env.stream_response do |&on_data|
response = client.call(request)

save_response(env, response.status, nil, response.headers, finished: false)

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

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

Expand Down
14 changes: 9 additions & 5 deletions test/async/http/faraday/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,20 @@ def get_response(url = bound_url, path = '/index', adapter_options: {})
builder.adapter :async_http
end

chunks = []
streamed = []
env = nil

response = client.get(bound_url) do |request|
request.options.on_data = proc do |chunk|
chunks << chunk
request.options.on_data = proc do |chunk, size, block_env|
streamed << [chunk, size]
env ||= block_env
end
end

expect(response.body).to be_nil
expect(chunks).to be == ["chunk0", "chunk1", "chunk2"]
expect(response.body).to be(:empty?)
expect(streamed).to be == [["chunk0", 6], ["chunk1", 12], ["chunk2", 18]]
expect(env).to be_a(Faraday::Env)
expect(env.status).to be == 200
end
end
end
Expand Down
Loading