Class: HTTP::Request
- Inherits:
- 
      Object
      
        - Object
- HTTP::Request
 
- Defined in:
- lib/bogo/http_proxy.rb
Overview
NOTE: This is a simple monkey patch to the httprb library to provide implicit proxy support to requests. It is defined within this library to allow easy sharing. It is the responsibility of the user to ensure the http gem is available!
Instance Method Summary collapse
- 
  
    
      #proxy  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Override to implicitly apply proxy as required. 
- 
  
    
      #proxy_connect_header  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Compute HTTP request header SSL proxy connection. 
- 
  
    
      #proxy_is_allowed?  ⇒ TrueClass, FalseClass 
    
    
  
  
  
  
  
  
  
  
  
    Check ‘ENV` and disable proxy if endpoint is listed. 
Instance Method Details
#proxy ⇒ Object
Override to implicitly apply proxy as required
NOTE: If dealing with https request, force port so CONNECT request will properly include destination port
| 14 15 16 17 18 19 20 21 22 23 24 25 26 | # File 'lib/bogo/http_proxy.rb', line 14 def proxy if((@proxy.nil? || @proxy.empty?) && ENV["#{uri.scheme}_proxy"] && proxy_is_allowed?) _proxy = URI.parse(ENV["#{uri.scheme}_proxy"]) Hash.new.tap do |opts| opts[:proxy_address] = _proxy.host opts[:proxy_port] = _proxy.port opts[:proxy_username] = _proxy.user if _proxy.user opts[:proxy_password] = _proxy.password if _proxy.password end else @proxy if proxy_is_allowed? end end | 
#proxy_connect_header ⇒ Object
Compute HTTP request header SSL proxy connection
NOTE: Provide override to get port included within request
| 44 45 46 47 48 49 50 51 52 53 54 55 | # File 'lib/bogo/http_proxy.rb', line 44 def proxy_connect_header if(@uri.port.nil?) if(@uri.scheme == 'https') dest_port = 443 else dest_port = 80 end else dest_port = @uri.port end "CONNECT #{@uri.host}:#{dest_port} HTTP/#{version}" end | 
#proxy_is_allowed? ⇒ TrueClass, FalseClass
Check ‘ENV` and disable proxy if endpoint is listed
| 31 32 33 34 35 36 37 38 39 | # File 'lib/bogo/http_proxy.rb', line 31 def proxy_is_allowed? if(ENV['no_proxy']) ENV['no_proxy'].to_s.split(',').map(&:strip).none? do |item| File.fnmatch(item, [uri.host, uri.port].compact.join(':')) end else true end end |