0

I have a really weird problem where when i try to access a URL using RestClient it times out. If i access the URL directly from the shell (using curl) it loads fine. I can get to other URLs, like google, via RestClient.

Furthermore, if i use Net::HTTP directly and send a GET request it goes through (!!).

I suspect that RestClient is not constructing the request appropriately but I'm not sure how to get RestClient to log out anything useful. I also have no idea how to access the request it's generating.

How can i see the complete http request that RestClient is making?

Below is some code outlining the problem:

irb(main):002:0> RestClient.log
=> nil
irb(main):003:0> RestClient.get my_bad_uri
RestClient::RequestTimeout: Request Timeout
    from /myapp/vendor/bundle/ruby/2.1.0/gems/rest-client-1.7.2/lib/restclient/request.rb:427:in `rescue in transmit'
    from /myapp/vendor/bundle/ruby/2.1.0/gems/rest-client-1.7.2/lib/restclient/request.rb:350:in `transmit'
    from /myapp/vendor/bundle/ruby/2.1.0/gems/rest-client-1.7.2/lib/restclient/request.rb:176:in `execute'
    from /myapp/vendor/bundle/ruby/2.1.0/gems/rest-client-1.7.2/lib/restclient/request.rb:41:in `execute'
    from /myapp/vendor/bundle/ruby/2.1.0/gems/rest-client-1.7.2/lib/restclient.rb:65:in `get'
    from (irb):3
    from /myapp/vendor/bundle/ruby/2.1.0/gems/railties-3.2.18/lib/rails/commands/console.rb:47:in `start'
    from /myapp/vendor/bundle/ruby/2.1.0/gems/railties-3.2.18/lib/rails/commands/console.rb:8:in `start'
    from /myapp/vendor/bundle/ruby/2.1.0/gems/railties-3.2.18/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:33:in `require'
    from script/rails:33:in `<main>'

irb(main):004:0> RestClient.get "https://google.com" #google works
=> "<!doctype html><html itemscope=\"\" itemtype=\"http://schema.org/WebPage\" lang=\"en\"><head><meta content=\"Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.\" name=\"description\"><meta content=\"noodp\" name=\"robots\"><meta content=\"/images/google_favicon_128.png\" itemprop=\"image\"><title>Google</title><script>(function(){window.google={kEI:'WjDtU_GDMo_8oAT0woBw',kEXPI:'4791,17259,4000116,4003510,4007661,4008142,4009033,4010073,4010806,4010858,4010899,4011228,4011258,4011679,4012373,4012504,4013414,4013591,4013723,4013823,4013967,4013979,4014016,4014033,4014431,4014515,4014636,4014805,4014991,4015234,4015266,4015550,4015587,4015772,4016127,4016279,4016309,4016373,4016487,4016824,4016976,4017204,4017285,4017595,4017639,4

Thank you!

SharkLaser
  • 713
  • 1
  • 10
  • 19
  • Use [wireshark](https://www.wireshark.org/) to analyze the network traffic. Of course, you could use Ethereal, or tcpdump, or... well, you get the idea. A network analyzer. There are a _lot_ of them. – Parthian Shot Aug 14 '14 at 22:02
  • @ParthianShot For reasons beyond the scope of this comment, that's not an option for me :/ – SharkLaser Aug 14 '14 at 22:11

1 Answers1

0

Since there are some lines of code referenced in the error logs, and a rescue block specifically (/lib/restclient/request.rb:427:in 'rescue in transmit'), you could open the gem and add some logging/puts/ statements in those methods to try and figure out where in the chain this is hanging up. It's not super surgical but it could get you headed in the right direction. If you are using bundler, I believe you can run bundle open restclient and then dig into the source code of the gem.

Jacques Betancourt
  • 2,652
  • 3
  • 18
  • 19