Method: CloudLB::Connection#lbreq
- Defined in:
- lib/cloudlb/connection.rb
#lbreq(method, server, path, port, scheme, headers = {}, data = nil, attempts = 0) ⇒ Object
This method actually makes the HTTP REST calls out to the server. Relies on the thread-safe typhoeus gem to do the heavy lifting. Never called directly.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/cloudlb/connection.rb', line 147 def lbreq(method,server,path,port,scheme,headers = {},data = nil,attempts = 0) # :nodoc: if data unless data.is_a?(IO) headers['Content-Length'] = data.respond_to?(:lstat) ? data.stat.size : data.size end else headers['Content-Length'] = 0 end hdrhash = headerprep(headers) url = "#{scheme}://#{server}#{path}" print "DEBUG: Data is #{data}\n" if (data && ENV['LOADBALANCERS_VERBOSE']) request = Typhoeus::Request.new(url, :body => data, :method => method.downcase.to_sym, :headers => hdrhash, :verbose => ENV['LOADBALANCERS_VERBOSE'] ? true : false) CloudLB.hydra.queue(request) CloudLB.hydra.run response = request.response print "DEBUG: Body is #{response.body}\n" if ENV['LOADBALANCERS_VERBOSE'] raise CloudLB::Exception::ExpiredAuthToken if response.code.to_s == "401" response rescue Errno::EPIPE, Errno::EINVAL, EOFError # Server closed the connection, retry raise CloudLB::Exception::Connection, "Unable to reconnect to #{server} after #{attempts} attempts" if attempts >= 5 attempts += 1 @http[server].finish if @http[server].started? start_http(server,path,port,scheme,headers) retry rescue CloudLB::Exception::ExpiredAuthToken raise CloudLB::Exception::Connection, "Authentication token expired and you have requested not to retry" if @retry_auth == false CloudLB::Authentication.new(self) retry end |