Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions lib/webmock/http_lib_adapters/async_http_client_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,18 @@ def webmock_responses
@webmock_responses ||= {}
end

def strip_header?(key:, value:)
# WebMock's internal processing will not handle the body
# correctly if the header indicates that it is chunked, unless
# we also create all the chunks.
# It's far easier just to remove the header.
key =~ /transfer-encoding/i && value =~/chunked/i
end

def build_response(webmock_response)
headers = (webmock_response.headers || {}).each_with_object([]) do |(k, value), o|
next if strip_header?(key: k, value: value)

Array(value).each do |v|
o.push [k, v]
end
Expand Down
5 changes: 5 additions & 0 deletions spec/acceptance/async_http_client/async_http_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@
)
end

it 'works with responses that use chunked transfer encoding' do
stub_request(:get, "www.example.com").to_return(body: "abc", headers: { 'Transfer-Encoding' => 'chunked' })
expect(http_request(:get, "http://www.example.com").body).to eq("abc")
end

it 'works with to_timeout' do
stub_request(:get, 'http://www.example.com').to_timeout
expect { make_request(:get, 'http://www.example.com') }.to raise_error Async::TimeoutError
Expand Down