Object
Wraps up OpenSSL::SSL::SSLSocket and offers debugging features.
# File lib/httpclient/session.rb, line 236
236: def initialize(socket, context, debug_dev = nil)
237: unless SSLEnabled
238: raise ConfigurationError.new('Ruby/OpenSSL module is required')
239: end
240: @context = context
241: @socket = socket
242: @ssl_socket = create_openssl_socket(@socket)
243: @debug_dev = debug_dev
244: end
# File lib/httpclient/session.rb, line 301
301: def <<(str)
302: rv = @ssl_socket.write(str)
303: debug(str)
304: rv
305: end
# File lib/httpclient/session.rb, line 270
270: def close
271: @ssl_socket.close
272: @socket.close
273: end
# File lib/httpclient/session.rb, line 275
275: def closed?
276: @socket.closed?
277: end
# File lib/httpclient/session.rb, line 279
279: def eof?
280: @ssl_socket.eof?
281: end
# File lib/httpclient/session.rb, line 307
307: def flush
308: @ssl_socket.flush
309: end
# File lib/httpclient/session.rb, line 283
283: def gets(*args)
284: str = @ssl_socket.gets(*args)
285: debug(str)
286: str
287: end
# File lib/httpclient/session.rb, line 266
266: def peer_cert
267: @ssl_socket.peer_cert
268: end
# File lib/httpclient/session.rb, line 250
250: def post_connection_check(host)
251: verify_mode = @context.verify_mode || OpenSSL::SSL::VERIFY_NONE
252: if verify_mode == OpenSSL::SSL::VERIFY_NONE
253: return
254: elsif @ssl_socket.peer_cert.nil? and
255: check_mask(verify_mode, OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT)
256: raise OpenSSL::SSL::SSLError.new('no peer cert')
257: end
258: hostname = host.host
259: if @ssl_socket.respond_to?(:post_connection_check) and RUBY_VERSION > "1.8.4"
260: @ssl_socket.post_connection_check(hostname)
261: else
262: @context.post_connection_check(@ssl_socket.peer_cert, hostname)
263: end
264: end
# File lib/httpclient/session.rb, line 289
289: def read(*args)
290: str = @ssl_socket.read(*args)
291: debug(str)
292: str
293: end
# File lib/httpclient/session.rb, line 295
295: def readpartial(*args)
296: str = @ssl_socket.readpartial(*args)
297: debug(str)
298: str
299: end
# File lib/httpclient/session.rb, line 246
246: def ssl_connect
247: @ssl_socket.connect
248: end
# File lib/httpclient/session.rb, line 321
321: def check_mask(value, mask)
322: value & mask == mask
323: end
# File lib/httpclient/session.rb, line 325
325: def create_openssl_socket(socket)
326: ssl_socket = nil
327: if OpenSSL::SSL.const_defined?("SSLContext")
328: ctx = OpenSSL::SSL::SSLContext.new
329: @context.set_context(ctx)
330: ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ctx)
331: else
332: ssl_socket = OpenSSL::SSL::SSLSocket.new(socket)
333: @context.set_context(ssl_socket)
334: end
335: ssl_socket
336: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.