Sunday 23 November 2014

Ruby and NO_PROXY

Proxy Servers

Like most people where they work there is always a proxy server present.  Love them or hate them they are here to stay. Recently where I am working we faced a problem. All the HTTP traffic is going thorough the proxy. However there was a specific case where we did not want it to.

The Problem

When we sent a request to a URL lets call it (please note that this is an internal address) it would resolve to a load balanced address. For some reason (I'm not a networking guy) the proxy could not connect to it.

The Solution

What I needed to do was the following:

  1. I edited the /etc/hosts file and added IP_ADDRESS
  2. I added export no_proxy="" so it does not use the proxy. 
However the fun did not stop there. We were using Faraday to connect to this server. What I realised is that the default Ruby HTTP implementation does not honour no_proxy environment variable. So after some researching I found that httpclient does. So all I needed to do is install the gem and then use it:

conn = '') do |faraday|
  faraday.request  :url_encoded
  faraday.response :logger
  faraday.adapter  :excon

Call conn.get and everything worked.

As I found it hard to find a solution I thought I would write it down for someone else to find it useful.

No comments:

Post a Comment