lib/3scale/client/http_client.rb in 3scale_client-2.7.0 vs lib/3scale/client/http_client.rb in 3scale_client-2.8.0

- old
+ new

@@ -16,27 +16,29 @@ def initialize(options) @secure = !!options[:secure] @host = options.fetch(:host) @persistent = options[:persistent] + @port = options[:port] || (@secure ? 443 : 80) backend_class = @persistent ? self.class.persistent_backend : NetHttp or raise PersistenceNotAvailable backend_class.prepare - @http = backend_class.new(@host) + @http = backend_class.new(@host, @port) @http.ssl! if @secure end class BaseClient def self.available? end def self.prepare end - def initialize(host) + def initialize(host, port) @host = host + @port = port end def get_request(path) get = Net::HTTP::Get.new(path) get.add_field(*USER_CLIENT_HEADER) @@ -63,11 +65,11 @@ def self.prepare require 'net/http/persistent' end - def initialize(host) + def initialize(host, port) super @http = ::Net::HTTP::Persistent.new @protocol = 'http' end @@ -85,24 +87,24 @@ uri = full_uri(path) @http.request(uri, post_request(path, payload)) end def full_uri(path) - URI.join "#{@protocol}://#{@host}", path + URI.join "#{@protocol}://#{@host}:#{@port}", path end end class NetHttp < BaseClient extend Forwardable def_delegators :@http, :use_ssl?, :active? - def initialize(host) + def initialize(host, port) super - @http = Net::HTTP.new(@host, 80) + @http = Net::HTTP.new(@host, port) end def ssl! - @http = Net::HTTP.new(@host, 443) + @http = Net::HTTP.new(@host, @port) @http.use_ssl = true end def get(path) @http.request get_request(path)