Sha256: 618c2765cf5ee6496a1ce5ad2e73548232ea80b9d4ade27acf15faba88f83487

Contents?: true

Size: 1.02 KB

Versions: 17

Compression:

Stored size: 1.02 KB

Contents

# encoding: utf-8
module ProxyTester
  class HttpProxy

    private

    attr_reader :user

    public

    attr_reader :host, :port

    def initialize(connection_string)
      match = connection_string_pattern.match(connection_string) || {}

      raise Exceptions::ProxyConnectionStringInvalid, JSON.dump(connection_string: connection_string) if match[:host].blank?
      raise Exceptions::ProxyConnectionStringInvalid, JSON.dump(connection_string: connection_string) if match[:port].blank?

      @host = match[:host]
      @port = match[:port]
    end

    def use_user(user)
      @user = user
    end

    def to_string(options = {})
      result = []
      result << 'http://'

      if user and options[:cleartext] == true
        result << "#{user.name}:#{user.password}@" 
      elsif user
        result << "#{user.name}:#{'*' * 4}@" if user
      end

      result << "#{host}:#{port}"

      result.join
    end

    private

    def connection_string_pattern
      /(?<host>[[:alnum:]._-]+):(?<port>\d+{1,5})/
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
proxy_tester-0.1.10 lib/proxy_tester/http_proxy.rb
proxy_tester-0.1.8 lib/proxy_tester/http_proxy.rb
proxy_tester-0.1.6 lib/proxy_tester/http_proxy.rb
proxy_tester-0.1.5 lib/proxy_tester/http_proxy.rb
proxy_tester-0.1.4 lib/proxy_tester/http_proxy.rb
proxy_tester-0.1.3 lib/proxy_tester/http_proxy.rb
proxy_tester-0.1.2 lib/proxy_tester/http_proxy.rb
proxy_tester-0.1.1 lib/proxy_tester/http_proxy.rb
proxy_tester-0.1.0 lib/proxy_tester/http_proxy.rb
proxy_tester-0.0.9 lib/proxy_tester/http_proxy.rb
proxy_tester-0.0.8 lib/proxy_tester/http_proxy.rb
proxy_tester-0.0.7 lib/proxy_tester/http_proxy.rb
proxy_tester-0.0.6 lib/proxy_tester/http_proxy.rb
proxy_tester-0.0.5 lib/proxy_tester/http_proxy.rb
proxy_tester-0.0.4 lib/proxy_tester/http_proxy.rb
proxy_tester-0.0.3 lib/proxy_tester/http_proxy.rb
proxy_tester-0.0.2 lib/proxy_tester/http_proxy.rb