Last active
April 26, 2018 14:25
-
-
Save jrafanie/e9e279320ed5a68142c510168e851eec to your computer and use it in GitHub Desktop.
Debug faraday requests in ManageIQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# put me in config/initializers | |
# restart your appliances and it should now log all the net/http interactions | |
# ***** WARNING ***** | |
# do not run in production, set_debug_output has this warning in ruby docs: | |
# WARNING This method opens a serious security hole. Never use this method in production code. | |
require 'manageiq-api-client' | |
require 'faraday' | |
require 'faraday/adapter/net_http' | |
module FaradayDebug | |
def net_http_connection(env) | |
super.tap do |http| | |
http.set_debug_output($log) | |
$log.info("XXX #{Process.pid} faraday debug: #{http.read_timeout}") | |
$log.info("XXX #{Process.pid} faraday debug: #{http.open_timeout}") | |
http.read_timeout = 300 | |
http.open_timeout = 300 | |
$log.info("XXX #{Process.pid} faraday debug: #{http.read_timeout}") | |
$log.info("XXX #{Process.pid} faraday debug: #{http.open_timeout}") | |
end | |
end | |
end | |
Faraday::Adapter::NetHttp.prepend(FaradayDebug) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# you can run an individual request with plain ruby by setting the requested url and user/password | |
# | |
# ***** WARNING ***** | |
# do not run in production, set_debug_output has this warning in ruby docs: | |
# WARNING This method opens a serious security hole. Never use this method in production code. | |
require 'manageiq-api-client' | |
require 'faraday' | |
require 'faraday/adapter/net_http' | |
module FaradayDebug | |
def net_http_connection(env) | |
super.tap do |http| | |
http.set_debug_output($stderr) | |
$stderr.puts http.read_timeout | |
$stderr.puts http.open_timeout | |
http.read_timeout = 300 | |
http.open_timeout = 300 | |
$stderr.puts http.read_timeout | |
$stderr.puts http.open_timeout | |
end | |
end | |
end | |
Faraday::Adapter::NetHttp.prepend(FaradayDebug) | |
ManageIQ::API::Client.new(:url => 'http://localhost:3000', :user => 'XXX', :password => 'XXX'); nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment