Implementation was copied from @kaiwren's script.
net-http-debug is a simple Ruby gem that provides an easy way to enable and disable HTTP debugging for Net::HTTP in Rails development environment. It allows you to quickly toggle debug output for all Net::HTTP requests, which can be incredibly useful when troubleshooting API integrations or network-related issues.
Add this line to your application's Gemfile:
gem 'net-http-debug'And then execute:
$ bundle install
Or install it yourself as:
$ gem install net-http-debug
To use Net::HTTP Debug in your Rails application, first require it:
require 'net-http-debug'To enable debug mode, which will output all Net::HTTP requests and responses to STDERR, use:
Net::HTTP.enable_debug!This will modify all subsequent Net::HTTP requests to output debug information.
To disable debug mode and return to normal operation:
Net::HTTP.disable_debug!The enable_debug! method includes a safeguard to prevent accidental usage in non-development environments. It will raise an exception if called outside of the Rails development environment.
Here's a quick example of how you might use Net::HTTP Debug in a Rails console or application:
require 'net-http-debug'
# Enable debugging
Net::HTTP.enable_debug!
# Make a request
Net::HTTP.get(URI('https://api.example.com/data'))
# You'll see detailed output of the request and response
# Disable debugging when you're done
Net::HTTP.disable_debug!After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install.
Bug reports and pull requests are welcome on GitHub at https://github.com/andreibondarev/net-http-debug. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Net::HTTP Debug project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.