Class: HTTPClient::SSLSocketWrap

Inherits:
Object
  • Object
show all
Defined in:
lib/httpclient.rb

Overview

HTTPClient::SSLSocketWrap

Instance Method Summary collapse

Constructor Details

#initialize(socket, context, debug_dev = nil) ⇒ SSLSocketWrap

Returns a new instance of SSLSocketWrap.



938
939
940
941
942
943
944
945
946
947
# File 'lib/httpclient.rb', line 938

def initialize(socket, context, debug_dev = nil)
  unless SSLEnabled
    raise RuntimeError.new(
      "Ruby/OpenSSL module is required for https access.")
  end
  @context = context
  @socket = socket
  @ssl_socket = create_ssl_socket(@socket)
  @debug_dev = debug_dev
end

Instance Method Details

#<<(str) ⇒ Object



1007
1008
1009
1010
1011
# File 'lib/httpclient.rb', line 1007

def <<(str)
  rv = @ssl_socket.write(str)
  @debug_dev << str if @debug_dev
  rv
end

#addrObject



978
979
980
# File 'lib/httpclient.rb', line 978

def addr
  @socket.addr
end

#closeObject



982
983
984
985
# File 'lib/httpclient.rb', line 982

def close
  @ssl_socket.close
  @socket.close
end

#closed?Boolean

Returns:

  • (Boolean)


987
988
989
# File 'lib/httpclient.rb', line 987

def closed?
  @socket.closed?
end

#eof?Boolean

Returns:

  • (Boolean)


991
992
993
# File 'lib/httpclient.rb', line 991

def eof?
  @ssl_socket.eof?
end

#flushObject



1013
1014
1015
# File 'lib/httpclient.rb', line 1013

def flush
  @ssl_socket.flush
end

#gets(*args) ⇒ Object



995
996
997
998
999
# File 'lib/httpclient.rb', line 995

def gets(*args)
  str = @ssl_socket.gets(*args)
  @debug_dev << str if @debug_dev
  str
end

#peer_certObject



974
975
976
# File 'lib/httpclient.rb', line 974

def peer_cert
  @ssl_socket.peer_cert
end

#post_connection_check(host) ⇒ Object



953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
# File 'lib/httpclient.rb', line 953

def post_connection_check(host)
  verify_mode = @context.verify_mode || OpenSSL::SSL::VERIFY_NONE
  if verify_mode == OpenSSL::SSL::VERIFY_NONE
    return
  elsif @ssl_socket.peer_cert.nil? and
      check_mask(verify_mode, OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT)
    raise OpenSSL::SSL::SSLError, "no peer cert"
  end
  hostname = host.host
#    if @ssl_socket.respond_to?(:post_connection_check)
#      ## modified by =vg to catch wildcard hostnames
#      begin
#        @ssl_socket.post_connection_check(hostname)
#      rescue OpenSSL::SSL::SSLError
#        @ssl_socket.post_connection_check(hostname.sub(/^[^.]+/, '*'))
#      end
#    else
    @context.post_connection_check(@ssl_socket.peer_cert, hostname)
#    end
end

#read(*args) ⇒ Object



1001
1002
1003
1004
1005
# File 'lib/httpclient.rb', line 1001

def read(*args)
  str = @ssl_socket.read(*args)
  @debug_dev << str if @debug_dev
  str
end

#ssl_connectObject



949
950
951
# File 'lib/httpclient.rb', line 949

def ssl_connect
  @ssl_socket.connect
end

#syncObject



1017
1018
1019
# File 'lib/httpclient.rb', line 1017

def sync
  @ssl_socket.sync
end

#sync=(sync) ⇒ Object



1021
1022
1023
# File 'lib/httpclient.rb', line 1021

def sync=(sync)
  @ssl_socket.sync = sync
end