Commit 258b63ca57c2d952fca940580aae332e861b5401
1 parent
e73614db
Exists in
staging
and in
4 other branches
Added a way to set a proxy for feed handler
Showing
2 changed files
with
9 additions
and
1 deletions
Show diff stats
lib/feed_handler.rb
@@ -42,7 +42,9 @@ class FeedHandler | @@ -42,7 +42,9 @@ class FeedHandler | ||
42 | if !valid_url?(address) | 42 | if !valid_url?(address) |
43 | raise InvalidUrl.new("\"%s\" is not a valid URL" % address) | 43 | raise InvalidUrl.new("\"%s\" is not a valid URL" % address) |
44 | end | 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 | end | 48 | end |
47 | return content | 49 | return content |
48 | rescue Exception => ex | 50 | rescue Exception => ex |
test/unit/feed_handler_test.rb
@@ -141,4 +141,10 @@ class FeedHandlerTest < ActiveSupport::TestCase | @@ -141,4 +141,10 @@ class FeedHandlerTest < ActiveSupport::TestCase | ||
141 | end | 141 | end |
142 | end | 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 | end | 150 | end |