Commit 258b63ca57c2d952fca940580aae332e861b5401

Authored by Victor Costa
1 parent e73614db

Added a way to set a proxy for feed handler

lib/feed_handler.rb
... ... @@ -42,7 +42,9 @@ class FeedHandler
42 42 if !valid_url?(address)
43 43 raise InvalidUrl.new("\"%s\" is not a valid URL" % address)
44 44 end
45   - open(address, "User-Agent" => "Noosfero/#{Noosfero::VERSION}", &block)
  45 + header = {"User-Agent" => "Noosfero/#{Noosfero::VERSION}"}
  46 + header.merge!(:proxy => ENV['FEED_HTTP_PROXY']) if ENV['FEED_HTTP_PROXY']
  47 + open(address, header, &block)
46 48 end
47 49 return content
48 50 rescue Exception => ex
... ...
test/unit/feed_handler_test.rb
... ... @@ -141,4 +141,10 @@ class FeedHandlerTest < ActiveSupport::TestCase
141 141 end
142 142 end
143 143  
  144 + should 'set proxy when FEED_HTTP_PROXY is setted from env' do
  145 + ENV.stubs('[]').with('FEED_HTTP_PROXY').returns('http://127.0.0.1:3128')
  146 + handler.expects(:open).with('http://site.org/feed.xml', {"User-Agent" => "Noosfero/#{Noosfero::VERSION}", :proxy => 'http://127.0.0.1:3128'}, anything).returns('bli content')
  147 + assert_equal 'bli content', handler.fetch('http://site.org/feed.xml')
  148 + end
  149 +
144 150 end
... ...