Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 57 additions and 6 deletions.
  1. +3 −4 .kick
  2. +22 −2 lib/rest/request.rb
  3. +32 −0 test/rest_request_test.rb
View
7 .kick
@@ -3,7 +3,7 @@ ignore(/^(html|tmp|support)/)
recipe :ruby
-class Ruby
+class Kicker::Recipes::Ruby
def self.is_test_file?(path)
path if File.exist?(File.expand_path("../#{path}", __FILE__))
end
@@ -16,13 +16,12 @@ process do |files|
end
end
-recipe :ruby
process do |files|
- Ruby.run_tests(files.take_and_map do |file|
+ Kicker::Recipes::Ruby.run_tests(files.take_and_map do |file|
case file
when %r{^lib/(.+)\.rb$}
path = $1.gsub('/', '_')
- Ruby.is_test_file?("test/#{path}_test.rb")
+ Kicker::Recipes::Ruby.is_test_file?("test/#{path}_test.rb")
end
end)
end
View
24 lib/rest/request.rb
@@ -73,6 +73,26 @@ def path
[url.path, url.query].compact.join('?')
end
+ def http_proxy
+ ENV['HTTP_PROXY'] || ENV['http_proxy']
+ end
+
+ def proxy_settings
+ http_proxy ? URI.parse(http_proxy) : nil
+ end
+
+ def proxy
+ @proxy ||= Net::HTTP.Proxy(proxy_settings.host, proxy_settings.port, proxy_settings.user, proxy_settings.password)
+ end
+
+ def http_request
+ if proxy_settings
+ proxy.new(url.host, url.port)
+ else
+ Net::HTTP.new(url.host, url.port)
+ end
+ end
+
# Performs the actual request and returns a REST::Response object with the response
def perform
case verb
@@ -95,8 +115,8 @@ def perform
if options[:username] and options[:password]
request.basic_auth(options[:username], options[:password])
end
-
- http_request = Net::HTTP.new(url.host, url.port)
+
+ http_request = http_request()
# enable SSL/TLS
if url.scheme == 'https'
View
32 test/rest_request_test.rb
@@ -169,4 +169,36 @@
REST.get('/something')
}.should.raise(REST::DisconnectedError)
end
+
+ it "should find proxy settings from the environment" do
+ request = REST::Request.new(:get, URI.parse(''))
+ request.http_proxy.should.be.nil
+
+ ENV['HTTP_PROXY'] = 'http://localhost'
+ request.http_proxy.should. == 'http://localhost'
+ ENV.delete('HTTP_PROXY')
+
+ ENV['http_proxy'] = 'http://rob:secret@192.168.0.1:21'
+ request.http_proxy.should. == 'http://rob:secret@192.168.0.1:21'
+ ENV.delete('http_proxy')
+ end
+
+ it "parses the http proxy settings" do
+ request = REST::Request.new(:get, URI.parse(''))
+ request.stubs(:http_proxy).returns('http://rob:secret@192.168.0.1:21')
+ request.proxy_settings.host.should == '192.168.0.1'
+ request.proxy_settings.port.should == 21
+ request.proxy_settings.user.should == 'rob'
+ request.proxy_settings.password.should == 'secret'
+ end
+
+ it "should use a proxy when the http_proxy" do
+ request = REST::Request.new(:get, URI.parse(''))
+ request.http_request.should.be.kind_of?(Net::HTTP)
+ request.http_request.proxy_address.should.be.nil
+
+ request.stubs(:http_proxy).returns('http://192.168.0.1:80')
+ request.http_request.should.be.kind_of?(Net::HTTP)
+ request.http_request.proxy_address.should == '192.168.0.1'
+ end
end

No commit comments for this range

Something went wrong with that request. Please try again.