Commit e5be1a6
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.
Use String#dup to maintain encoding per feedback
Co-authored-by: Koichi ITO <koic.ito@gmail.com>1 parent 5c99e1a commit e5be1a6
2 files changed
Lines changed: 14 additions & 1 deletion
File tree
- lib/webmock/http_lib_adapters
- spec/acceptance/typhoeus
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
| 175 | + | |
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
128 | 141 | | |
129 | 142 | | |
130 | 143 | | |
| |||
0 commit comments