mod_rails and environment variables, proxy setting for ruby-openid

The ruby-openid library has support for deployments behind a corporate proxy, but you have to enable it programmatically. Place this in environment.rb after the Rails::Initializer block.


ENV['HTTP_PROXY'] = "http://myproxy"
ENV['HTTPS_PROXY'] = "http://myproxy"
ENV['http_proxy'] = "http://myproxy"
ENV['https_proxy'] = "http://myproxy"
require 'openid'
OpenID.fetcher = OpenID.fetcher_use_env_http_proxy

The below was written when I did not know what I was doing (and arguably, I still don't).


It seems that mod_rails does not pass environment variables down to ruby.

This is the cause of some pain when trying to use ruby-openid when behind a proxy. In openid/fetchers.rb, ruby-openid tries to read the http_proxy environment variable.

So I manually changed StandardFetcher.initialize to have this:


proxy_string = proxy url string as in the environment variable http_proxy
proxy_uri = URI.parse(proxy_string)
proxy_addr = proxy_uri.host
proxy_port = proxy_uri.port
proxy_user = proxy_uri.user
proxy_pass = proxy_uri.password
@proxy = Net::HTTP::Proxy(proxy_addr, proxy_port, proxy_user, proxy_pass)

(Yes this is REALLY ugly. But I just wanted it to work on this system.)