lib/vra/http.rb in vmware-vra-2.7.1 vs lib/vra/http.rb in vmware-vra-2.7.2
- old
+ new
@@ -1,21 +1,22 @@
# frozen_string_literal: true
-require "net/http"
-require "openssl"
+require "net/http" unless defined?(Net::HTTP)
+require "openssl" unless defined?(OpenSSL)
module Vra
module Http
def self.execute(params)
request = Request.new(params)
response = request.call
response = response.forward(request).call until response.final?
if ENV["VRA_HTTP_TRACE"]
puts "#{request.params[:method].upcase} #{request.params[:url]}" unless request.params.nil?
- puts ">>>>> #{JSON.parse(request.params[:payload]).to_json}" unless request.params[:payload].nil?
+ puts ">>>>> #{JSON.parse(request.params[:payload]).to_json.gsub(/\"password\":\"(.+)\",/, '"password":"********",' )}" unless request.params[:payload].nil?
puts "<<<<< #{JSON.parse(response.body).to_json}" unless response.body.nil?
end
raise error(response) unless response.success?
+
response
end
def self.error(response)
Error.from_response(response)
@@ -27,11 +28,11 @@
def initialize(params)
@params = params
end
def redirectable?
- [:get, :head].include?(params[:method])
+ %i{get head}.include?(params[:method])
end
def redirect_to(location)
new(url: location)
end
@@ -73,10 +74,11 @@
self.class.new(params.dup.merge(new_params))
end
def verify_ssl?
return true if params[:verify_ssl].nil?
+
params[:verify_ssl]
end
end
class Response
@@ -87,9 +89,10 @@
end
def forward(request)
if redirect?
raise Http.error(self) unless request.redirectable?
+
request.redirect_to(location)
elsif see_other?
request.see_other(location)
else
request