Skip to content

Commit

Permalink
Merge pull request #17 from iron-io/http-proxy
Browse files Browse the repository at this point in the history
http_proxy support.
  • Loading branch information
treeder committed Feb 25, 2015
2 parents 65e4c29 + bc43df9 commit b3fdf90
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/rest/client.rb
Expand Up @@ -50,6 +50,7 @@ def self.backing_gems
class Client

attr_accessor :options, :logger, :gem
attr_reader :wrapper
# options:
# - :gem => specify gem explicitly
#
Expand All @@ -70,7 +71,7 @@ def initialize(options={})
@logger.debug "Using excon gem."
elsif @gem == :typhoeus
require File.expand_path('wrappers/typhoeus_wrapper', File.dirname(__FILE__))
@wrapper = Rest::Wrappers::TyphoeusWrapper.new
@wrapper = Rest::Wrappers::TyphoeusWrapper.new(self)
@logger.debug "Using typhoeus gem."
elsif @gem == :net_http_persistent
require File.expand_path('wrappers/net_http_persistent_wrapper', File.dirname(__FILE__))
Expand All @@ -82,10 +83,12 @@ def initialize(options={})
hint = (options[:gem] ? "" : "NOTICE: Please install 'typhoeus' gem or upgrade to Ruby 2.X for optimal performance.")
puts hint
@logger.debug "Using rest-client gem. #{hint}"
RestClient.proxy = options[:http_proxy] if options[:http_proxy]
else # use internal client
require File.expand_path('wrappers/internal_client_wrapper', File.dirname(__FILE__))
@wrapper = Rest::Wrappers::InternalClientWrapper.new
@logger.debug "Using rest internal client. #{hint}"
InternalClient.proxy = options[:http_proxy] if options[:http_proxy]
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/rest/wrappers/net_http_persistent_wrapper.rb
Expand Up @@ -54,7 +54,8 @@ class NetHttpPersistentWrapper < BaseWrapper

def initialize(client)
@client = client
@http = Net::HTTP::Persistent.new 'rest_gem'
@http = Net::HTTP::Persistent.new('rest_gem')
@http.proxy = URI(@client.options[:http_proxy]) if @client.options[:http_proxy]
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end

Expand Down
5 changes: 5 additions & 0 deletions lib/rest/wrappers/typhoeus_wrapper.rb
Expand Up @@ -33,6 +33,10 @@ def headers_orig

class TyphoeusWrapper < BaseWrapper

def initialize(client)
@client = client
end

def default_typhoeus_options
req_hash = {}
# todo: should change this timeout to longer if it's for posting file
Expand All @@ -46,6 +50,7 @@ def default_typhoeus_options

def get(url, req_hash={})
req_hash = default_typhoeus_options.merge(req_hash)
req_hash[:proxy] = @client.options[:http_proxy] if @client.options[:http_proxy]
# puts "REQ_HASH=" + req_hash.inspect
response = Typhoeus::Request.get(url, req_hash)
#p response
Expand Down
1 change: 0 additions & 1 deletion test/tmp.rb
Expand Up @@ -8,7 +8,6 @@ def setup

end


def test_post_file
r = @rest.post_file("http://httpbin.org/post", :params=>{:q => "Rick Astley"})
p r
Expand Down

0 comments on commit b3fdf90

Please sign in to comment.