Class: Net::HTTP::ConnectionPool::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/net/http/connection_pool/session.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_session, key) ⇒ Session

Returns a new instance of Session.



23
24
25
26
27
28
# File 'lib/net/http/connection_pool/session.rb', line 23

def initialize http_session, key
  @http_session = http_session
  @key = key
  @created_at = Time.now
  @last_used_at = nil
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



34
35
36
# File 'lib/net/http/connection_pool/session.rb', line 34

def created_at
  @created_at
end

#http_sessionObject (readonly)

Returns the value of attribute http_session.



30
31
32
# File 'lib/net/http/connection_pool/session.rb', line 30

def http_session
  @http_session
end

#keyObject (readonly)

Returns the value of attribute key.



32
33
34
# File 'lib/net/http/connection_pool/session.rb', line 32

def key
  @key
end

#last_used_atObject (readonly)

Returns the value of attribute last_used_at.



36
37
38
# File 'lib/net/http/connection_pool/session.rb', line 36

def last_used_at
  @last_used_at
end

Class Method Details

.for(connection, open_timeout) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/net/http/connection_pool/session.rb', line 55

def for connection, open_timeout

  http_args = []
  http_args << connection.host
  http_args << connection.port
  if connection.proxy?
    http_args << connection.proxy_address
    http_args << connection.proxy_port
    http_args << connection.proxy_user
    http_args << connection.proxy_password
  end

  http = Net::HTTP.new(*http_args)
  #http.set_debug_output($stdout)
  http.open_timeout = open_timeout

  if connection.ssl?
    http.use_ssl = true
    if connection.ssl_verify_peer?
      http.verify_mode = OpenSSL::SSL::VERIFY_PEER
      http.ca_file = connection.ssl_ca_file if connection.ssl_ca_file
      http.ca_path = connection.ssl_ca_path if connection.ssl_ca_path
    else
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end
  else
    http.use_ssl = false
  end

  http.start

  Session.new(http, connection.key)

end

Instance Method Details

#finishnil

Returns:

  • (nil)


45
46
47
48
49
50
51
# File 'lib/net/http/connection_pool/session.rb', line 45

def finish
  begin
    http_session.finish if http_session.started?
  rescue IOError
  end
  nil
end

#request(*args, &block) ⇒ Object



38
39
40
41
42
# File 'lib/net/http/connection_pool/session.rb', line 38

def request *args, &block
  response = http_session.request(*args, &block)
  @last_used_at = Time.now
  response
end