Project

General

Profile

« Previous | Next » 

Revision 8efc06c3

Added by Šimon Lukašík over 9 years ago

Fixes #7922 - promote uri and http to instance property

This will allow to re-use existing http connection for subsequent
requests.

View differences:

lib/proxy/request.rb
module Proxy::HttpRequest
class ForemanRequest
def send_request(path, body)
uri = URI.parse(Proxy::SETTINGS.foreman_url.to_s)
path = [uri.path, path].join('/') unless uri.path.empty?
req = Net::HTTP::Post.new(URI.join(uri.to_s, path).path)
req.add_field('Accept', 'application/json,version=2')
req.content_type = 'application/json'
req.body = body
http.request(req)
end
def uri
@uri ||= URI.parse(Proxy::SETTINGS.foreman_url.to_s)
end
def http
@http ||= http_init
end
private
def http_init
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == 'https'
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
......
http.key = OpenSSL::PKey::RSA.new(File.read(private_key), nil)
end
end
path = [uri.path, path].join('/') unless uri.path.empty?
req = Net::HTTP::Post.new(URI.join(uri.to_s, path).path)
req.add_field('Accept', 'application/json,version=2')
req.content_type = 'application/json'
req.body = body
http.request(req)
return http
end
end

Also available in: Unified diff