Class: HTTPClient::SSLSocket

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

Overview

Wraps up OpenSSL::SSL::SSLSocket and offers debugging features.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of SSLSocket.



32
33
34
35
36
37
38
39
40
# File 'lib/httpclient/ssl_socket.rb', line 32

def initialize(socket, context, debug_dev = nil)
  unless SSLEnabled
    raise ConfigurationError.new('Ruby/OpenSSL module is required')
  end
  @socket = socket
  @context = context
  @ssl_socket = create_openssl_socket(@socket)
  @debug_dev = debug_dev
end

Class Method Details

.create_socket(session) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/httpclient/ssl_socket.rb', line 16

def self.create_socket(session)
  site = session.proxy || session.dest
  socket = session.create_socket(site.host, site.port)
  begin
    if session.proxy
      session.connect_ssl_proxy(socket, Util.urify(session.dest.to_s))
    end
    ssl_socket = new(socket, session.ssl_config, session.debug_dev)
    ssl_socket.ssl_connect(session.dest.host)
    ssl_socket
  rescue
    socket.close
    raise
  end
end

Instance Method Details

#<<(str) ⇒ Object



92
93
94
95
96
# File 'lib/httpclient/ssl_socket.rb', line 92

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

#closeObject



61
62
63
64
# File 'lib/httpclient/ssl_socket.rb', line 61

def close
  @ssl_socket.close
  @socket.close
end

#closed?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/httpclient/ssl_socket.rb', line 66

def closed?
  @socket.closed?
end

#eof?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/httpclient/ssl_socket.rb', line 70

def eof?
  @ssl_socket.eof?
end

#flushObject



98
99
100
# File 'lib/httpclient/ssl_socket.rb', line 98

def flush
  @ssl_socket.flush
end

#gets(rs) ⇒ Object



74
75
76
77
78
# File 'lib/httpclient/ssl_socket.rb', line 74

def gets(rs)
  str = @ssl_socket.gets(rs)
  debug(str)
  str
end

#peer_certObject



57
58
59
# File 'lib/httpclient/ssl_socket.rb', line 57

def peer_cert
  @ssl_socket.peer_cert
end

#read(size, buf = nil) ⇒ Object



80
81
82
83
84
# File 'lib/httpclient/ssl_socket.rb', line 80

def read(size, buf = nil)
  str = @ssl_socket.read(size, buf)
  debug(str)
  str
end

#readpartial(size, buf = nil) ⇒ Object



86
87
88
89
90
# File 'lib/httpclient/ssl_socket.rb', line 86

def readpartial(size, buf = nil)
  str = @ssl_socket.readpartial(size, buf)
  debug(str)
  str
end

#ssl_connect(hostname = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/httpclient/ssl_socket.rb', line 42

def ssl_connect(hostname = nil)
  if hostname && @ssl_socket.respond_to?(:hostname=)
    @ssl_socket.hostname = hostname
  end
  @ssl_socket.connect
  if $DEBUG
    if @ssl_socket.respond_to?(:ssl_version)
      warn("Protocol version: #{@ssl_socket.ssl_version}")
    end
    warn("Cipher: #{@ssl_socket.cipher.inspect}")
    warn("State: #{@ssl_socket.state}")
  end
  post_connection_check(hostname)
end

#syncObject



102
103
104
# File 'lib/httpclient/ssl_socket.rb', line 102

def sync
  @ssl_socket.sync
end

#sync=(sync) ⇒ Object



106
107
108
# File 'lib/httpclient/ssl_socket.rb', line 106

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