Class: HTTPClient::SSLSocketWrap

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

Overview

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of SSLSocketWrap.



262
263
264
265
266
267
268
269
270
# File 'lib/httpclient/session.rb', line 262

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

Instance Method Details

#<<(str) ⇒ Object



330
331
332
333
334
# File 'lib/httpclient/session.rb', line 330

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

#closeObject



299
300
301
302
# File 'lib/httpclient/session.rb', line 299

def close
  @ssl_socket.close
  @socket.close
end

#closed?Boolean

Returns:

  • (Boolean)


304
305
306
# File 'lib/httpclient/session.rb', line 304

def closed?
  @socket.closed?
end

#eof?Boolean

Returns:

  • (Boolean)


308
309
310
# File 'lib/httpclient/session.rb', line 308

def eof?
  @ssl_socket.eof?
end

#flushObject



336
337
338
# File 'lib/httpclient/session.rb', line 336

def flush
  @ssl_socket.flush
end

#gets(*args) ⇒ Object



312
313
314
315
316
# File 'lib/httpclient/session.rb', line 312

def gets(*args)
  str = @ssl_socket.gets(*args)
  debug(str)
  str
end

#peer_certObject



295
296
297
# File 'lib/httpclient/session.rb', line 295

def peer_cert
  @ssl_socket.peer_cert
end

#post_connection_check(host) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/httpclient/session.rb', line 279

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.new('no peer cert')
  end
  hostname = host.host
  if @ssl_socket.respond_to?(:post_connection_check) and RUBY_VERSION > "1.8.4"
    @ssl_socket.post_connection_check(hostname)
  else
    @context.post_connection_check(@ssl_socket.peer_cert, hostname)
  end
end

#read(*args) ⇒ Object



318
319
320
321
322
# File 'lib/httpclient/session.rb', line 318

def read(*args)
  str = @ssl_socket.read(*args)
  debug(str)
  str
end

#readpartial(*args) ⇒ Object



324
325
326
327
328
# File 'lib/httpclient/session.rb', line 324

def readpartial(*args)
  str = @ssl_socket.readpartial(*args)
  debug(str)
  str
end

#ssl_connect(hostname = nil) ⇒ Object



272
273
274
275
276
277
# File 'lib/httpclient/session.rb', line 272

def ssl_connect(hostname = nil)
  if hostname && @ssl_socket.respond_to?(:hostname=)
    @ssl_socket.hostname = hostname
  end
  @ssl_socket.connect
end

#syncObject



340
341
342
# File 'lib/httpclient/session.rb', line 340

def sync
  @ssl_socket.sync
end

#sync=(sync) ⇒ Object



344
345
346
# File 'lib/httpclient/session.rb', line 344

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