Class: MintHttp::NetHttpFactory
- Inherits:
-
Object
- Object
- MintHttp::NetHttpFactory
- Defined in:
- lib/mint_http/net_http_factory.rb
Instance Method Summary collapse
- #client_namespace(hostname, port, options = {}) ⇒ Object
- #defaults(options = {}) ⇒ Object
-
#make_client(hostname, port, options = {}) ⇒ Object
Available options: proxy_address proxy_port proxy_user proxy_pass open_timeout write_timeout read_timeout ssl_timeout ca_file cert key verify_mode verify_hostname.
Instance Method Details
#client_namespace(hostname, port, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mint_http/net_http_factory.rb', line 14 def client_namespace(hostname, port, = {}) = defaults() host_group = "#{hostname.downcase}_#{port.to_s.downcase}" proxy_group = "#{[:proxy_address]}_#{[:proxy_port]}_#{[:proxy_user]}" timeout_group = "#{[:open_timeout]}_#{[:write_timeout]}_#{[:read_timeout]}" cert_signature = [:cert]&.serial&.to_s key_signature = OpenSSL::Digest::SHA1.new([:key]&.to_der || '').to_s ssl_group = "#{[:use_ssl]}_#{[:ssl_timeout]}_#{[:ca_file]}_#{cert_signature}_#{key_signature}_#{[:verify_mode]}_#{[:verify_hostname]}" "#{host_group}_#{proxy_group}_#{timeout_group}_#{ssl_group}" end |
#defaults(options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/mint_http/net_http_factory.rb', line 4 def defaults( = {}) [:open_timeout] = [:open_timeout] || 5 [:write_timeout] = [:write_timeout] || 5 [:read_timeout] = [:read_timeout] || 20 [:ssl_timeout] = [:ssl_timeout] || 5 [:verify_mode] = [:verify_mode] || OpenSSL::SSL::VERIFY_PEER [:verify_hostname] = [:verify_hostname] || true end |
#make_client(hostname, port, options = {}) ⇒ Object
Available options: proxy_address proxy_port proxy_user proxy_pass open_timeout write_timeout read_timeout ssl_timeout ca_file cert key verify_mode verify_hostname
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/mint_http/net_http_factory.rb', line 42 def make_client(hostname, port, = {}) = defaults() net_http = Net::HTTP.new(hostname, port, nil) # Disable retries net_http.max_retries = 0 # Set proxy options net_http.proxy_address = [:proxy_address] net_http.proxy_port = [:proxy_port] net_http.proxy_user = [:proxy_user] net_http.proxy_pass = [:proxy_pass] # Timeout net_http.open_timeout = [:open_timeout] net_http.write_timeout = [:write_timeout] net_http.read_timeout = [:read_timeout] # SSL options net_http.use_ssl = [:use_ssl] net_http.ssl_timeout = [:ssl_timeout] net_http.cert = [:cert] net_http.key = [:key] net_http.verify_mode = [:verify_mode] net_http.verify_hostname = [:verify_hostname] if OpenSSL::X509::Store === [:ca] net_http.cert_store = [:ca] else net_http.ca_file = [:ca] end net_http end |