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

- (SSLSocketWrap) initialize(socket, context, debug_dev = nil)

A new instance of SSLSocketWrap



289
290
291
292
293
294
295
296
297
# File 'lib/httpclient/session.rb', line 289

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

- (Object) <<(str)



369
370
371
372
373
# File 'lib/httpclient/session.rb', line 369

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

- (Object) close



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

def close
  @ssl_socket.close
  @socket.close
end

- (Boolean) closed?

Returns:

  • (Boolean)


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

def closed?
  @socket.closed?
end

- (Boolean) eof?

Returns:

  • (Boolean)


347
348
349
# File 'lib/httpclient/session.rb', line 347

def eof?
  @ssl_socket.eof?
end

- (Object) flush



375
376
377
# File 'lib/httpclient/session.rb', line 375

def flush
  @ssl_socket.flush
end

- (Object) gets(*args)



351
352
353
354
355
# File 'lib/httpclient/session.rb', line 351

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

- (Object) peer_cert



334
335
336
# File 'lib/httpclient/session.rb', line 334

def peer_cert
  @ssl_socket.peer_cert
end

- (Object) post_connection_check(host)



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/httpclient/session.rb', line 306

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

- (Object) read(*args)



357
358
359
360
361
# File 'lib/httpclient/session.rb', line 357

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

- (Object) readpartial(*args)



363
364
365
366
367
# File 'lib/httpclient/session.rb', line 363

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

- (Object) ssl_cipher



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

def ssl_cipher
  @ssl_socket.cipher
end

- (Object) ssl_connect(hostname = nil)



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

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

- (Object) ssl_state



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

def ssl_state
  @ssl_socket.state
end

- (Object) ssl_version



322
323
324
# File 'lib/httpclient/session.rb', line 322

def ssl_version
  @ssl_socket.ssl_version if @ssl_socket.respond_to?(:ssl_version)
end

- (Object) sync



379
380
381
# File 'lib/httpclient/session.rb', line 379

def sync
  @ssl_socket.sync
end

- (Object) sync=(sync)



383
384
385
# File 'lib/httpclient/session.rb', line 383

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