Class: HttpConnectionOptions
- Inherits:
-
Object
- Object
- HttpConnectionOptions
- Defined in:
- lib/em-http/http_connection_options.rb
Instance Attribute Summary collapse
-
#bind ⇒ Object
readonly
Returns the value of attribute bind.
-
#bind_port ⇒ Object
readonly
Returns the value of attribute bind_port.
-
#connect_timeout ⇒ Object
readonly
Returns the value of attribute connect_timeout.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#https ⇒ Object
writeonly
Sets the attribute https.
-
#inactivity_timeout ⇒ Object
readonly
Returns the value of attribute inactivity_timeout.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#tls ⇒ Object
readonly
Returns the value of attribute tls.
Instance Method Summary collapse
- #connect_proxy? ⇒ Boolean
- #http_proxy? ⇒ Boolean
-
#initialize(uri, options) ⇒ HttpConnectionOptions
constructor
A new instance of HttpConnectionOptions.
- #proxy_from_env ⇒ Object
- #socks_proxy? ⇒ Boolean
Constructor Details
#initialize(uri, options) ⇒ HttpConnectionOptions
Returns a new instance of HttpConnectionOptions.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/em-http/http_connection_options.rb', line 6 def initialize(uri, ) @connect_timeout = [:connect_timeout] || 5 # default connection setup timeout @inactivity_timeout = [:inactivity_timeout] ||= 10 # default connection inactivity (post-setup) timeout @tls = [:tls] || [:ssl] || {} if bind = [:bind] @bind = bind[:host] || '0.0.0.0' # Eventmachine will open a UNIX socket if bind :port # is explicitly set to nil @bind_port = bind[:port] end uri = uri.kind_of?(Addressable::URI) ? uri : Addressable::URI::parse(uri.to_s) @https = uri.scheme == "https" uri.port ||= (@https ? 443 : 80) @tls[:sni_hostname] = uri.hostname @proxy = [:proxy] || proxy_from_env if proxy @host = proxy[:host] @port = proxy[:port] else @host = uri.hostname @port = uri.port end end |
Instance Attribute Details
#bind ⇒ Object (readonly)
Returns the value of attribute bind.
2 3 4 |
# File 'lib/em-http/http_connection_options.rb', line 2 def bind @bind end |
#bind_port ⇒ Object (readonly)
Returns the value of attribute bind_port.
2 3 4 |
# File 'lib/em-http/http_connection_options.rb', line 2 def bind_port @bind_port end |
#connect_timeout ⇒ Object (readonly)
Returns the value of attribute connect_timeout.
3 4 5 |
# File 'lib/em-http/http_connection_options.rb', line 3 def connect_timeout @connect_timeout end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
2 3 4 |
# File 'lib/em-http/http_connection_options.rb', line 2 def host @host end |
#https=(value) ⇒ Object (writeonly)
Sets the attribute https
4 5 6 |
# File 'lib/em-http/http_connection_options.rb', line 4 def https=(value) @https = value end |
#inactivity_timeout ⇒ Object (readonly)
Returns the value of attribute inactivity_timeout.
3 4 5 |
# File 'lib/em-http/http_connection_options.rb', line 3 def inactivity_timeout @inactivity_timeout end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
2 3 4 |
# File 'lib/em-http/http_connection_options.rb', line 2 def port @port end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
2 3 4 |
# File 'lib/em-http/http_connection_options.rb', line 2 def proxy @proxy end |
#tls ⇒ Object (readonly)
Returns the value of attribute tls.
2 3 4 |
# File 'lib/em-http/http_connection_options.rb', line 2 def tls @tls end |
Instance Method Details
#connect_proxy? ⇒ Boolean
40 41 42 |
# File 'lib/em-http/http_connection_options.rb', line 40 def connect_proxy? @proxy && (@proxy[:type] == :http || @proxy[:type].nil?) && @https end |
#http_proxy? ⇒ Boolean
36 37 38 |
# File 'lib/em-http/http_connection_options.rb', line 36 def http_proxy? @proxy && (@proxy[:type] == :http || @proxy[:type].nil?) && !@https end |
#proxy_from_env ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/em-http/http_connection_options.rb', line 48 def proxy_from_env # TODO: Add support for $http_no_proxy or $no_proxy ? proxy_str = if @https ENV['HTTPS_PROXY'] || ENV['https_proxy'] else ENV['HTTP_PROXY'] || ENV['http_proxy'] # Fall-back to $ALL_PROXY if none of the above env-vars have values end || ENV['ALL_PROXY'] # Addressable::URI::parse will return `nil` if given `nil` and an empty URL for an empty string # so, let's short-circuit that: return if !proxy_str || proxy_str.empty? proxy_env_uri = Addressable::URI::parse(proxy_str) { :host => proxy_env_uri.host, :port => proxy_env_uri.port, :type => :http } rescue Addressable::URI::InvalidURIError # An invalid env-var shouldn't crash the config step, IMHO. # We should somehow log / warn about this, perhaps... return end |
#socks_proxy? ⇒ Boolean
44 45 46 |
# File 'lib/em-http/http_connection_options.rb', line 44 def socks_proxy? @proxy && (@proxy[:type] == :socks5) end |