Created
May 23, 2017 18:53
-
-
Save danajp/ecaedcbbe6a9590d13b3b246498cd6ee to your computer and use it in GitHub Desktop.
[net http blog] net/http
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Net #:nodoc: | |
# ... | |
class HTTP < Protocol | |
# ... | |
SSL_IVNAMES = [ | |
:@ca_file, | |
:@ca_path, | |
:@cert, | |
:@cert_store, | |
:@ciphers, | |
:@key, | |
:@ssl_timeout, | |
:@ssl_version, | |
:@verify_callback, | |
:@verify_depth, | |
:@verify_mode, | |
] | |
SSL_ATTRIBUTES = [ | |
:ca_file, | |
:ca_path, | |
:cert, | |
:cert_store, | |
:ciphers, | |
:key, | |
:ssl_timeout, | |
:ssl_version, | |
:verify_callback, | |
:verify_depth, | |
:verify_mode, | |
] | |
# ... | |
def connect | |
# ... | |
if use_ssl? | |
ssl_parameters = Hash.new | |
iv_list = instance_variables | |
SSL_IVNAMES.each_with_index do |ivname, i| | |
if iv_list.include?(ivname) and | |
value = instance_variable_get(ivname) | |
ssl_parameters[SSL_ATTRIBUTES[i]] = value if value | |
end | |
end | |
@ssl_context = OpenSSL::SSL::SSLContext.new | |
@ssl_context.set_params(ssl_parameters) | |
D "starting SSL for #{conn_address}:#{conn_port}..." | |
s = OpenSSL::SSL::SSLSocket.new(s, @ssl_context) | |
s.sync_close = true | |
D "SSL established" | |
end | |
# ... | |
end | |
# ... | |
end | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment