Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveResource & HTTP proxy support

#2133

The ActiveResource::Connection#help method does not support HTTP proxy connections.

Fix:

def http
  http = http_agent.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 # If timeout is not set, the default Net::HTTP timeout (60s) is used.
  http
end

def http_agent
  unless @http_agent
    proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']
    if proxy
      proxy = URI.parse(ENV['HTTP_PROXY'] || ENV['http_proxy'])
      @http_agent = Net::HTTP::Proxy(proxy.host,proxy.port)
    else
      @http_agent = Net::HTTP
    end
  end
  @http_agent
end

Reported by Sébastien Dabet · March 5th, 2009 @ 09:43 AM

State: committed
Milestone: 2.3.4
Assigned to: nobody
Importance: none

Activity

  1. Rainer Jung
    Rainer Jung

    I like this. I could really need this.

    April 7th, 2009 @ 12:33 PM

  2. Marshall Huss
    Marshall Huss

    I was just working on a fix for this. Would it be more desirable to use the environment settings or let it be explicitly set in the ActiveResource model?

    May 15th, 2009 @ 07:40 PM

  3. Marshall Huss
    Marshall Huss

    Here's my patch to add proxy support. I made it work as close to the site attribute as possible. In reference to the paste-in-patch, I believe if the user wants to use the environmental http_proxy variable then they can explicitly set it.

    class Foo < ActiveResource::Base
    self.site = "http://site.local" self.proxy = "http://user:password@proxy.local:10000" end

    If you have any suggestions/issues let me know and I can make the changes.

    May 18th, 2009 @ 04:16 AM

  4. Marshall Huss
    Marshall Huss

    Found an issue with the patch and it will not work, will submit a new one asap.

    May 18th, 2009 @ 05:36 PM

  5. Jer
    Jer

    This is exactly what I have been looking for! Well done and thanks.

    May 18th, 2009 @ 06:53 PM

  6. John Wunder
    John Wunder

    Thanks Marshall, this will really help us out at work since we're behind a proxy, been missing it.

    May 18th, 2009 @ 06:55 PM

  7. Brennan Dunn
  8. David
    David

    This is excellent and exactly what I need for work. +1

    May 18th, 2009 @ 07:06 PM

  9. Jay Crossler
  10. Marshall Huss
    Marshall Huss

    I added some more tests and fixed a bug.

    class Foo < ActiveResource::Base
      self.site = "http://localhost"
      self.proxy = "http://user:password@proxy.local:8080"
    end
    

    May 19th, 2009 @ 12:03 AM

  11. Geoff
    Geoff

    +1 on this

    I work in one of those lovely corporate settings where this would be really useful.

    May 19th, 2009 @ 04:05 PM

  12. Rizwan Reza
    Rizwan Reza

    not reproducible

    -1 The patch doesn't apply... neither 2-3-stable nor master.

    August 8th, 2009 @ 09:32 PM

  13. Marshall Huss
  14. Marshall Huss
    Marshall Huss
    • Tag changed from active_resource, proxy to active_resource, bugmash, proxy

    August 8th, 2009 @ 10:12 PM

  15. Marshall Huss
  16. Jeremy Kemper
    Jeremy Kemper
    • State changed from new to committed
    • Milestone changed from 2.x to 2.3.4

    2-3-stable: 791c3880393c671c3b101ea9b12836070df7a64d

    master: 4d1552810f631898c3d7f758454c92ca35a8cb26

    August 8th, 2009 @ 11:42 PM

  17. Marshall Huss
    Marshall Huss
    • Tag changed from active_resource, bugmash, proxy to active_resource, proxy

    August 9th, 2009 @ 12:37 AM

  18. Marshall Huss
  19. Marshall Huss