Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bblimke/webmock
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.25.0
Choose a base ref
...
head repository: bblimke/webmock
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.25.1
Choose a head ref
  • 5 commits
  • 13 files changed
  • 2 contributors

Commits on Feb 7, 2025

  1. Update required_ruby_version to 2.6+

    Follow-up to 4b85495.
    koic committed Feb 7, 2025
    Copy the full SHA
    da93416 View commit details

Commits on Feb 11, 2025

  1. Remove useless encoding magic comment

    Script encoding has been set to UTF-8 by default since Ruby 2.0.
    Since WebMock supports Ruby 2.6 and above, these script encoding specification is unnecessary.
    koic committed Feb 11, 2025
    Copy the full SHA
    5c99e1a View commit details

Commits on Feb 20, 2025

  1. 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>
    patrickjaberg and koic committed Feb 20, 2025
    Copy the full SHA
    e5be1a6 View commit details
  2. Merge pull request #1078 from patrickjaberg/prj/2024.11.06/fix-frozen…

    …-typhoeus-streaming-response
    
    Fix FrozenError in Typhoeus streaming response body
    koic authored Feb 20, 2025
    Copy the full SHA
    371d01d View commit details

Commits on Mar 8, 2025

  1. Version 3.25.1

    koic committed Mar 8, 2025

    Verified

    This commit was signed with the committer’s verified signature.
    alejandrohdezma Alejandro Hernández
    Copy the full SHA
    f90fd50 View commit details
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

# 3.25.1

* Fix FrozenError in Typhoeus streaming response body

Thanks to [Patrick Jaberg](https://github.com/patrickjaberg)

# 3.25.0

* Resolve net-http adapter deprecation Ruby 3.4
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1207,6 +1207,7 @@ People who submitted patches and new features or suggested improvements. Many th
* Jacob Frautschi
* Christian Schmidt
* Rodrigo Argumedo
* Patrick Jaberg

For a full list of contributors you can visit the
[contributors](https://github.com/bblimke/webmock/contributors) page.
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
@@ -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)
2 changes: 1 addition & 1 deletion lib/webmock/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module WebMock
VERSION = '3.25.0' unless defined?(::WebMock::VERSION)
VERSION = '3.25.1' unless defined?(::WebMock::VERSION)
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
require 'spec_helper'
require 'acceptance/webmock_shared'
require_relative './async_http_client_spec_helper'
1 change: 0 additions & 1 deletion spec/acceptance/em_http_request/em_http_request_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
require 'spec_helper'
require 'acceptance/webmock_shared'
require 'ostruct'
2 changes: 0 additions & 2 deletions spec/acceptance/http_rb/http_rb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

require "spec_helper"
require "acceptance/webmock_shared"
require "acceptance/http_rb/http_rb_spec_helper"
2 changes: 0 additions & 2 deletions spec/acceptance/patron/patron_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

require 'spec_helper'
require 'acceptance/webmock_shared'

2 changes: 0 additions & 2 deletions spec/acceptance/shared/stubbing_requests.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

shared_examples_for "stubbing requests" do |*adapter_info|
describe "when requests are stubbed" do
describe "based on uri" do
13 changes: 13 additions & 0 deletions spec/acceptance/typhoeus/typhoeus_hydra_spec.rb
Original file line number Diff line number Diff line change
@@ -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'})
1 change: 0 additions & 1 deletion spec/unit/rack_response_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
require 'spec_helper'

describe WebMock::RackResponse do
1 change: 0 additions & 1 deletion spec/unit/util/parsers/json_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
require 'spec_helper'

describe WebMock::Util::Parsers::JSON do
3 changes: 1 addition & 2 deletions webmock.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path('../lib', __FILE__)
require 'webmock/version'

@@ -21,7 +20,7 @@ Gem::Specification.new do |s|
'wiki_uri' => 'https://github.com/bblimke/webmock/wiki'
}

s.required_ruby_version = '>= 2.5'
s.required_ruby_version = '>= 2.6'

s.add_dependency 'addressable', '>= 2.8.0'
s.add_dependency 'crack', '>= 0.3.2'