Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I view the HTTP response to an ActiveResource request?

I am trying to debug an ActiveResource call that is not working.

What's the best way to view the HTTP response to the request ActiveResource is making?

like image 919
Luke Francl Avatar asked Oct 22 '08 23:10

Luke Francl


2 Answers

Monkey patch the connection to enable Net::HTTP debug mode. See https://gist.github.com/591601 - I wrote it to solve precisely this problem. Adding this gist to your rails app will give you Net::HTTP.enable_debug! and Net::HTTP.disable_debug! that you can use to print debug info.

Net::HTTP debug mode is insecure and shouldn't be used in production, but is extremely informative for debugging.

like image 71
Kai Wren Avatar answered Sep 17 '22 15:09

Kai Wren


Add a new file to config/initializers/ called 'debug_connection.rb' with the following content:

class ActiveResource::Connection
  # Creates new Net::HTTP instance for communication with
  # remote service and resources.
  def http
    http = Net::HTTP.new(@site.host, @site.port)
    http.use_ssl = @site.is_a?(URI::HTTPS)
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl
    http.read_timeout = @timeout if @timeout
    # Here's the addition that allows you to see the output
    http.set_debug_output $stderr
    return http
  end
end

This will print the whole network traffic to $stderr.

like image 27
reto Avatar answered Sep 19 '22 15:09

reto