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



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

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

#closeObject



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

def close
  @ssl_socket.close
  @socket.close
end

#closed?Boolean

Returns:

  • (Boolean)


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

def closed?
  @socket.closed?
end

#eof?Boolean

Returns:

  • (Boolean)


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

def eof?
  @ssl_socket.eof?
end

#flushObject



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

def flush
  @ssl_socket.flush
end

#gets(rs) ⇒ Object



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

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

#peer_certObject



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

def peer_cert
  @ssl_socket.peer_cert
end

#read(size, buf = nil) ⇒ Object



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

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

#readpartial(size, buf = nil) ⇒ Object



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

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
# 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}")
  end
  post_connection_check(hostname)
end

#syncObject



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

def sync
  @ssl_socket.sync
end

#sync=(sync) ⇒ Object



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

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