Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #58 from jwilger/base_url_override

Allow Session.base_url to be overriden for specific requests
  • Loading branch information...
commit 5038613bcb7d47f3b2258a282781c916db1252ff 2 parents cf64602 + 9bbca67
@toland authored
Showing with 9 additions and 3 deletions.
  1. +4 −3 lib/patron/session.rb
  2. +5 −0 spec/session_spec.rb
View
7 lib/patron/session.rb
@@ -210,14 +210,15 @@ def request(action, url, headers, options = {})
req.upload_data = options[:data]
req.file_name = options[:file]
- url = self.base_url.to_s + url.to_s
- uri = URI.parse(url)
+ base_url = self.base_url.to_s
+ url = url.to_s
+ raise ArgumentError, "Empty URL" if base_url.empty? && url.empty?
+ uri = URI.join(base_url, url)
query = uri.query.to_s.split('&')
query += options[:query].is_a?(Hash) ? Util.build_query_pairs_from_hash(options[:query]) : options[:query].to_s.split('&')
uri.query = query.join('&')
uri.query = nil if uri.query.empty?
url = uri.to_s
- raise ArgumentError, "Empty URL" if url.empty?
req.url = url
handle_request(req)
View
5 spec/session_spec.rb
@@ -56,6 +56,11 @@
body.request_method.should == "GET"
end
+ it 'should ignore #base_url when a full URL is provided' do
+ @session.base_url = "http://example.com:123"
+ lambda { @session.get("http://localhost:9001/test") }.should_not raise_error(URI::InvalidURIError)
+ end
+
it "should download content with :get and a file path" do
tmpfile = "/tmp/patron_test.yaml"
response = @session.get_file "/test", tmpfile

1 comment on commit 5038613

@windy

good work

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