Skip to content
Browse files

Fix bug with em-http-request adapter.

Stubbed responses with a `Transer-Encoding: chunked` header
were not working properly.  WebMock's internal processing caused
the stubbed body to be ignored.
  • Loading branch information...
1 parent 769e997 commit 337740f9cc6a069da6fc7e955799d8a6f56dfa6b @myronmarston myronmarston committed Mar 24, 2011
Showing with 12 additions and 0 deletions.
  1. +7 −0 lib/webmock/http_lib_adapters/em_http_request.rb
  2. +5 −0 spec/em_http_request_spec.rb
View
7 lib/webmock/http_lib_adapters/em_http_request.rb
@@ -113,6 +113,13 @@ def make_raw_response(response)
headers.each do |header, value|
value = value.join(", ") if value.is_a?(Array)
+
+ # WebMock's internal processing will not handle the body
+ # correctly if the header indicates that it is chunked, unless
+ # we also create all the chunks.
+ # It's far easier just to remove the header.
+ next if header =~ /transfer-encoding/i && value =~/chunked/i
+
response_string << "#{header}: #{value}"
end if headers
View
5 spec/em_http_request_spec.rb
@@ -20,6 +20,11 @@
response.should == "abc"
end
+ it "should work with responses that use chunked transfer encoding" do
+ stub_http_request(:get, "www.example.com").to_return(:body => "abc", :headers => { 'Transfer-Encoding' => 'chunked' })
+ http_request(:get, "http://www.example.com").body.should == "abc"
+ end
+
it "should work with optional query params" do
stub_http_request(:get, "www.example.com/?x=3&a[]=b&a[]=c").to_return(:body => "abc")
http_request(:get, "http://www.example.com/?x=3", :query => {"a" => ["b", "c"]}).body.should == "abc"

0 comments on commit 337740f

Please sign in to comment.
Something went wrong with that request. Please try again.