Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Fix Rack response mutating request headers #367

merged 1 commit into from

2 participants


This came up when a before(:each) {} RSpec block set up a general Rack-backed stub for all requests to a domain and an individual spec placed a further expectation on the request for the Content-Type header. To our surprise, the Content-Type header was mysteriously vanishing.

@mattonrails and I traced it to WebMock and were able to write a failing test and fix the issue with no other failing specs. The spec we wrote is probably not in an ideal location so I'm happy to move it around with your feedback.

If you uncomment our diff in lib/webmock/rack_response.rb, you'll see the spec fail with the Accept header still present, but the Content-Type header missing and unable to be matched against.


@bjeanes @mattonrails thank you for fixing that!

@bblimke bblimke merged commit 5ea07eb into bblimke:master

1 check failed

Details default The Travis CI build could not complete due to an error

I'll move the spec to appropriate file.


Released as 1.17.3. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 11, 2014
  1. @bjeanes
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 1 deletion.
  1. +1 −1  lib/webmock/rack_response.rb
  2. +13 −0 spec/acceptance/webmock_shared.rb
2  lib/webmock/rack_response.rb
@@ -25,7 +25,7 @@ def body_from_rack_response(response)
def build_rack_env(request)
uri = request.uri
- headers = request.headers || {}
+ headers = (request.headers || {}).dup
body = request.body || ''
env = {
13 spec/acceptance/webmock_shared.rb
@@ -22,6 +22,19 @@
+ it "preserves content-type header when proxying to a rack app" do
+ stub_request(:any, //).to_rack(lambda {|req| [200, {}, ["OK"]] })
+ url = ""
+ headers = {
+ "Accept" => "application/json",
+ "Content-Type" => "application/json"
+ }
+ http_request(:get, url, :headers => headers)
+ WebMock.should have_requested(:get, url).with(:headers => headers)
+ end
include_context "allowing and disabling net connect", *adapter_info
include_context "stubbing requests", *adapter_info
Something went wrong with that request. Please try again.