31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/tlopo/request.rb', line 31
def run(&block)
instance_eval(&block) if block_given?
uri = URI(@url)
is_https = uri.scheme == 'https'
uri.path = '/' if uri.path.empty?
path = uri.path
unless uri.query.nil?
path = uri.query.empty? ? uri.path : "#{uri.path}?#{uri.query}"
end
req = Object.const_get("Net::HTTP::#{@method.capitalize}").new(path)
req.body = @payload
@headers&.each { |k, v| req[k] = v }
opts = {}
opts[:use_ssl] = is_https
opts[:verify_mode] = OpenSSL::SSL::VERIFY_NONE if is_https && @insecure
Net::HTTP.start(uri.host, uri.port, opts) do |http|
r = http.request(req)
msg = "HTTP_TRACE - code: #{r.code} method: #{@method}, url: #{@url},"
msg += " headers: #{@headers}, payload: #{@payload}"
LOGGER.debug msg if @http_trace
return r
end
end
|