Class: HT2P::Client
- Inherits:
-
Object
- Object
- HT2P::Client
- Extended by:
- Forwardable
- Defined in:
- lib/ht2p/client.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(uri, params = {}, &block) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(uri, params = {}, &block) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ht2p/client.rb', line 12 def initialize(uri, params={}, &block) @uri = URI.parse(uri) ip = IPSocket.getaddress(@uri.host) ip = nil if /\A127\.|\A::1\z/ =~ ip TCPSocket.open(ip, @uri.port) do |socket| if @uri.scheme == 'https' context = OpenSSL::SSL::SSLContext.new context.ca_file = params[:ca_file] context.ca_path = params[:ca_path] || OpenSSL::X509::DEFAULT_CERT_DIR context.timeout = params[:timeout] context.verify_depth = params[:verify_depth] context.verify_mode = OpenSSL::SSL.const_get\ "VERIFY_#{(params[:verify_mode] || 'PEER').to_s.upcase}" begin @socket = OpenSSL::SSL::SSLSocket.new(socket, context) @socket.connect @request = HT2P::Client::Request.new(self, params) block.call @request ensure @socket.close end else @socket = socket @request = HT2P::Client::Request.new(self, params) block.call @request end end end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
10 11 12 |
# File 'lib/ht2p/client.rb', line 10 def request @request end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
10 11 12 |
# File 'lib/ht2p/client.rb', line 10 def uri @uri end |