Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Clone the URI before mutating it. #184

Merged
merged 1 commit into from

2 participants

@jonleighton

The #build_request_signature method was mutating the URI if there were
any @req.query options. This means that if the request does actually get
sent, em-http-request appends the query to the URI a second time, and
the parameters are repeated.

For example:

EventMachine::HttpRequest.new('http://example.com/').get(:query => { :a => '1' })

would result in the follow URI being used for a live request:

http://example.com/?a=1&a=1

@jonleighton jonleighton Clone the URI before mutating it.
The #build_request_signature method was mutating the URI if there were
any @req.query options. This means that if the request does actually get
sent, em-http-request appends the query to the URI a second time, and
the parameters are repeated.

For example:

EventMachine::HttpRequest.new('http://example.com/').get(:query => { :a => '1' })

would result in the follow URI being used for a live request:

http://example.com/?a=1&a=1
6927943
@bblimke bblimke merged commit 887bf32 into bblimke:master
@bblimke
Owner

Looks good, it will be included in the next patch release this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 17, 2012
  1. @jonleighton

    Clone the URI before mutating it.

    jonleighton authored
    The #build_request_signature method was mutating the URI if there were
    any @req.query options. This means that if the request does actually get
    sent, em-http-request appends the query to the URI a second time, and
    the parameters are repeated.
    
    For example:
    
    EventMachine::HttpRequest.new('http://example.com/').get(:query => { :a => '1' })
    
    would result in the follow URI being used for a live request:
    
    http://example.com/?a=1&a=1
This page is out of date. Refresh to see the latest.
View
2  lib/webmock/http_lib_adapters/em_http_request/em_http_request_1_x.rb
@@ -153,7 +153,7 @@ def build_request_signature
end
method = @req.method
- uri = @req.uri
+ uri = @req.uri.clone
auth = @req.proxy[:authorization] if @req.proxy
query = @req.query
View
25 spec/acceptance/em_http_request/em_http_request_spec.rb
@@ -141,26 +141,41 @@ def response(resp)
end
describe "mocking EM::HttpClient API" do
+ let(:uri) { "http://www.example.com/" }
+
before do
- stub_request(:get, "www.example.com/")
+ stub_request(:get, uri)
WebMock::HttpLibAdapters::EmHttpRequestAdapter.enable!
end
- subject do
+
+ def client(uri, options = {})
client = nil
EM.run do
- client = EventMachine::HttpRequest.new('http://www.example.com/').get
+ client = EventMachine::HttpRequest.new(uri).get(options)
client.callback { EM.stop }
client.errback { failed }
end
client
end
+ subject { client(uri) }
+
it 'should support #uri' do
- subject.uri.should == Addressable::URI.parse('http://www.example.com/')
+ subject.uri.should == Addressable::URI.parse(uri)
end
it 'should support #last_effective_url' do
- subject.last_effective_url.should == Addressable::URI.parse('http://www.example.com/')
+ subject.last_effective_url.should == Addressable::URI.parse(uri)
+ end
+
+ context "with a query" do
+ let(:uri) { "http://www.example.com/?a=1&b=2" }
+ subject { client("http://www.example.com/?a=1", :query => { 'b' => 2 }) }
+
+ it "#request_signature doesn't mutate the original uri" do
+ subject.uri.should == Addressable::URI.parse("http://www.example.com/?a=1")
+ subject.request_signature.uri.should == Addressable::URI.parse(uri)
+ end
end
end
Something went wrong with that request. Please try again.