Skip to content

Instantly share code, notes, and snippets.

@gmhawash
Forked from brainlid/net_http_debug.rb
Created September 13, 2020 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmhawash/49f3267a0c5024d934cc38484bd5d22e to your computer and use it in GitHub Desktop.
Save gmhawash/49f3267a0c5024d934cc38484bd5d22e to your computer and use it in GitHub Desktop.
Enable debug for all Ruby HTTP requests
require 'net/http'
module Net
class HTTP
def self.enable_debug!
raise "You don't want to do this in anything but development mode!" unless Rails.env == 'development'
class << self
alias_method :__new__, :new
def new(*args, &blk)
instance = __new__(*args, &blk)
instance.set_debug_output($stderr)
instance
end
end
end
def self.disable_debug!
class << self
alias_method :new, :__new__
remove_method :__new__
end
end
end
end
# Net::HTTP.enable_debug!
# Net::HTTP.disable_debug!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment