@@ -448,18 +448,28 @@ class << self
448
448
#
449
449
# Creates a new instance of SSLSocket.
450
450
# _remote\_host_ and _remote_port_ are used to open TCPSocket.
451
- # If _context_ is provided,
452
- # the SSL Sockets initial params will be taken from the context.
453
451
# If _local\_host_ and _local\_port_ are specified,
454
452
# then those parameters are used on the local end to establish the connection.
453
+ # If _context_ is provided,
454
+ # the SSL Sockets initial params will be taken from the context.
455
455
#
456
- # === Example
457
- # ctx = OpenSSL::SSL::SSLContext.new
458
- # sock = OpenSSL::SSL::SSLSocket.open('localhost', 443, ctx )
456
+ # === Examples
457
+ #
458
+ # sock = OpenSSL::SSL::SSLSocket.open('localhost', 443)
459
459
# sock.connect # Initiates a connection to localhost:443
460
- def open ( remote_host , remote_port , context = nil , local_host = nil , local_port = nil )
460
+ #
461
+ # with SSLContext:
462
+ #
463
+ # ctx = OpenSSL::SSL::SSLContext.new
464
+ # sock = OpenSSL::SSL::SSLSocket.open('localhost', 443, context: ctx)
465
+ # sock.connect # Initiates a connection to localhost:443 with SSLContext
466
+ def open ( remote_host , remote_port , local_host = nil , local_port = nil , context : nil )
461
467
sock = ::TCPSocket . open ( remote_host , remote_port , local_host , local_port )
462
- OpenSSL ::SSL ::SSLSocket . new ( sock , context )
468
+ if context . nil?
469
+ return OpenSSL ::SSL ::SSLSocket . new ( sock )
470
+ else
471
+ return OpenSSL ::SSL ::SSLSocket . new ( sock , context )
472
+ end
463
473
end
464
474
end
465
475
end
0 commit comments