Class: Mechanize::Chain::SSLResolver
- Inherits:
-
Object
- Object
- Mechanize::Chain::SSLResolver
- Includes:
- Handler
- Defined in:
- lib/mechanize/chain/ssl_resolver.rb
Instance Attribute Summary
Attributes included from Handler
Instance Method Summary collapse
- #handle(ctx, params) ⇒ Object
-
#initialize(ca_file, verify_callback, cert, key, pass) ⇒ SSLResolver
constructor
A new instance of SSLResolver.
Constructor Details
#initialize(ca_file, verify_callback, cert, key, pass) ⇒ SSLResolver
Returns a new instance of SSLResolver.
6 7 8 9 10 11 12 |
# File 'lib/mechanize/chain/ssl_resolver.rb', line 6 def initialize(ca_file, verify_callback, cert, key, pass) @ca_file = ca_file @verify_callback = verify_callback @cert = cert @key = key @pass = pass end |
Instance Method Details
#handle(ctx, params) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mechanize/chain/ssl_resolver.rb', line 14 def handle(ctx, params) uri = params[:uri] http_obj = params[:connection] ssl = nil if http_obj.instance_variable_defined?(:@ssl_context) ssl = http_obj.instance_variable_get(:@ssl_context) end if uri.scheme == 'https' && ! http_obj.started? && (ssl.nil? || ! ssl.frozen?) http_obj.use_ssl = true http_obj.verify_mode = OpenSSL::SSL::VERIFY_NONE if @ca_file http_obj.ca_file = @ca_file http_obj.verify_mode = OpenSSL::SSL::VERIFY_PEER http_obj.verify_callback = @verify_callback if @verify_callback end if @cert && @key http_obj.cert = OpenSSL::X509::Certificate.new(::File.read(@cert)) http_obj.key = OpenSSL::PKey::RSA.new(::File.read(@key), @pass) end end super end |