Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix FrozenError in Typhoeus streaming response body
When stubbing a response for the Typhoeus adapter, and the Typhoeus request has an `on_body` callback, a `FrozenError` exception is raised when attempting to concatenate the current chunk of the response to the existing response body (i.e. `response.body << chunk`). FWIW, my use case for this is to abort a request as early as possible when the response body exceeds a given size, specifically when the response doesn't have a `Content-Length` header. The example below illustrates the issue: ```ruby require "bundler/inline" gemfile do source "https://rubygems.org" gem "typhoeus", "1.4.1" gem "webmock", "3.24.0" end WebMock.enable! WebMock.stub_request(:get, "https://example.com").to_return(status: "200", body: "body") request = Typhoeus::Request.new("https://example.com") request.on_body do |chunk, response| response.body << chunk end request.run ``` This change initializes the Typhoeus response body to a non-frozen, mutable string when using the `on_body` callback.
- Loading branch information