Skip to content

Commit 371d01d

Browse files
authored
Merge pull request #1078 from patrickjaberg/prj/2024.11.06/fix-frozen-typhoeus-streaming-response
Fix FrozenError in Typhoeus streaming response body
2 parents 5c99e1a + e5be1a6 commit 371d01d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def self.request_hash(request_signature)
172172
request.execute_headers_callbacks(response)
173173
end
174174
if request.respond_to?(:streaming?) && request.streaming?
175-
response.options[:response_body] = ""
175+
response.options[:response_body] = "".dup
176176
request.on_body.each { |callback| callback.call(webmock_response.body, response) }
177177
end
178178
request.finish(response)

spec/acceptance/typhoeus/typhoeus_hydra_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@
125125
expect(test_complete).to eq("")
126126
end
127127

128+
it "should initialize the streaming response body with a mutible (non-frozen) string" do
129+
skip("This test requires a newer version of Typhoeus") unless @request.respond_to?(:on_body)
130+
131+
stub_request(:any, "example.com").to_return(body: "body")
132+
133+
@request.on_body do |body_chunk, response|
134+
response.body << body_chunk
135+
end
136+
hydra.queue @request
137+
138+
expect{ hydra.run }.not_to raise_error
139+
end
140+
128141
it "should call on_headers with 2xx response" do
129142
body = "on_headers fired"
130143
stub_request(:any, "example.com").to_return(body: body, headers: {'X-Test' => '1'})

0 commit comments

Comments
 (0)