title: gem [Ruby] connecting through webproxy [windows]
body: <p>I'm asking this age-old question on how go through your proxy when using ruby gem.</p>
  
  <p>i tried setting the env variable <code>HTTP_PROXY</code>:</p>
  
  <pre><code>HTTP_PROXY=myusername:password@proxy.com:8080
  </code></pre>
  
  <p>but this does not work.</p>
  
  <pre><code>&gt; gem install rails
  ERROR:  While executing gem ... (URI::InvalidURIError)
      bad URI(is not URI?): http://myusername:password@proxy.com:8080
  </code></pre>
  
  <p>i tried using adding the <code>tcp://</code> at the start but it shows <code>http://tcp://</code> in the error message, so i assumed that was wrong too.</p>
  
  <p>So, i tried an automatic connect via php using this code:</p>
  
  <pre><code>&lt;?php
  $path = 'http://rubygems.org/';
  
  $auth = base64_encode('myusername:password');
  
  file_put_contents('proxy.log', 'POST::', FILE_APPEND);
  file_put_contents('proxy.log', print_r($_POST, true), FILE_APPEND);
  file_put_contents('proxy.log', 'GET::', FILE_APPEND);
  file_put_contents('proxy.log', print_r($_GET, true), FILE_APPEND);
  
  $aContext = array(
      'http' =&gt; array(
          'method' =&gt; 'GET',
          'content' =&gt; http_build_query($_GET),
          'proxy' =&gt; 'tcp://proxy.com:8080',
          'request_fulluri' =&gt; true,
          'header' =&gt; "Proxy-Authorization: Basic $auth"
      )
  );
  $cxContext = stream_context_create($aContext);
  
  $sFile = file_get_contents($path, false, $cxContext);
  
  header('Content-type: application/gzip');
  echo $sFile;
  </code></pre>
  
  <p>and incase it is trying to get a specific file, i handled it using apache.</p>
  
  <pre><code>.htaccess
  
  &lt;IfModule mod_rewrite.c&gt;
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} -d
      RewriteRule ^(.*[^/])$ http://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L] 
  
      RewriteCond $1 !^$
      RewriteCond $1 !^(index\.php)
      RewriteRule ^(.*)$ index.php?$1 [QSA,L]
  &lt;/IfModule&gt;
  # Options -Indexes
  </code></pre>
  
  <p>but still i get this error.</p>
  
  <pre><code>&gt; gem sources -ahttp://mylocalhost/ror-proxy/
  ERROR:  While executing gem ... (Zlib::GzipFile::Error)
  not in gzip format
  </code></pre>
  
  <p>Any ideas?</p>