Skip to content

Commit

Permalink
Merge pull request #1078 from patrickjaberg/prj/2024.11.06/fix-frozen…
Browse files Browse the repository at this point in the history
…-typhoeus-streaming-response

Fix FrozenError in Typhoeus streaming response body
  • Loading branch information
koic authored Feb 20, 2025
2 parents 5c99e1a + e5be1a6 commit 371d01d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def self.request_hash(request_signature)
request.execute_headers_callbacks(response)
end
if request.respond_to?(:streaming?) && request.streaming?
response.options[:response_body] = ""
response.options[:response_body] = "".dup
request.on_body.each { |callback| callback.call(webmock_response.body, response) }
end
request.finish(response)
Expand Down
13 changes: 13 additions & 0 deletions spec/acceptance/typhoeus/typhoeus_hydra_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@
expect(test_complete).to eq("")
end

it "should initialize the streaming response body with a mutible (non-frozen) string" do
skip("This test requires a newer version of Typhoeus") unless @request.respond_to?(:on_body)

stub_request(:any, "example.com").to_return(body: "body")

@request.on_body do |body_chunk, response|
response.body << body_chunk
end
hydra.queue @request

expect{ hydra.run }.not_to raise_error
end

it "should call on_headers with 2xx response" do
body = "on_headers fired"
stub_request(:any, "example.com").to_return(body: body, headers: {'X-Test' => '1'})
Expand Down

0 comments on commit 371d01d

Please sign in to comment.