title: use polipo to convert shadowsocks into an HTTP proxy
body: <p>My ssserver is started by docker image <a href="https://github.com/oddrationale/docker-shadowsocks" rel="nofollow noreferrer">oddrationale/docker-shadowsocks</a>:</p>
  
  <pre><code>docker run -d -p 1984:1984 oddrationale/docker-shadowsocks -s 0.0.0.0 -p 1984 -k paaassswwword -m aes-256-cfb
  </code></pre>
  
  <p>Then I use <code>sslocal</code> command to get local proxy. </p>
  
  <pre><code>sslocal -c /etc/shadowsocks.json -d start --pid-file /data/tmp/sslocal.pid --log-file /data/tmp/sslocal.log
  </code></pre>
  
  <p><code>/etc/shadowsocks.json</code> is like this:</p>
  
  <pre><code>{
    "server":"127.0.0.1",
    "server_port":1984,
    "local_address": "127.0.0.1",
    "local_port":1080,
    "password":"paaassswwword",
    "timeout":600,
    "method":"aes-256-cfb"
  }
  </code></pre>
  
  <p>I use <code>polipo</code> to convert shadowsocks to http proxy, my <code>/etc/polipo/config</code> is:</p>
  
  <pre><code>proxyAddress = 0.0.0.0
  socksProxyType = socks5
  socksParentProxy = 127.0.0.1:1080
  daemonise = true
  pidFile = /data/tmp/polipo.pid
  logFile = /data/tmp/polipo.log
  </code></pre>
  
  <p>I edit the iptables rules to make port 8123 can be accessed. I can access <code>http://host:8123</code> in browser, and the proxy looks work:</p>
  
  <pre><code>http_proxy=http://host:8123 curl -v google.com 
  </code></pre>
  
  <p>the output is like this:</p>
  
  <pre><code>* Rebuilt URL to: google.com/
  *   Trying host...
  * Connected to host (host) port 8123 (#0)
  &gt; GET HTTP://google.com/ HTTP/1.1
  &gt; Host: google.com
  &gt; User-Agent: curl/7.43.0
  &gt; Accept: */*
  &gt; Proxy-Connection: Keep-Alive
  &gt; 
  &lt; HTTP/1.1 302 Found
  &lt; Content-Length: 262
  &lt; Date: Thu, 13 Apr 2017 09:52:34 GMT
  &lt; Cache-Control: private
  &lt; Content-Type: text/html; charset=UTF-8
  &lt; Referrer-Policy: no-referrer
  &lt; Location: http://www.google.com.sg/?gfe_rd=cr&amp;ei=YkrvWPnOM-XLugTRgZDQBA
  &lt; Connection: keep-alive
  &lt; 
  &lt;HTML&gt;&lt;HEAD&gt;&lt;meta http-equiv="content-type" content="text/html;charset=utf-8"&gt;
  &lt;TITLE&gt;302 Moved&lt;/TITLE&gt;&lt;/HEAD&gt;&lt;BODY&gt;
  &lt;H1&gt;302 Moved&lt;/H1&gt;
  The document has moved
  &lt;A HREF="http://www.google.com.sg/?gfe_rd=cr&amp;amp;ei=YkrvWPnOM-XLugTRgZDQBA"&gt;here&lt;/A&gt;.
  &lt;/BODY&gt;&lt;/HTML&gt;
  * Connection #0 to host host left intact
  </code></pre>
  
  <p>The command does not always run successfully, and sometimes I get the following error:</p>
  
  <pre><code>* Rebuilt URL to: google.com/
  *   Trying host...
  * Connected to host (host) port 8123 (#0)
  &gt; GET HTTP://google.com/ HTTP/1.1
  &gt; Host: google.com
  &gt; User-Agent: curl/7.43.0
  &gt; Accept: */*
  &gt; Proxy-Connection: Keep-Alive
  &gt; 
  * Recv failure: Connection reset by peer
  * Closing connection 0
  curl: (56) Recv failure: Connection reset by peer
  </code></pre>
  
  <p>The output of <code>netstat -tlnp</code> is:</p>
  
  <pre><code>Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
  tcp        0      0 127.0.0.1:1080          0.0.0.0:*               LISTEN      5067/python     
  tcp        0      0 0.0.0.0:8123            0.0.0.0:*               LISTEN      9704/polipo     
  tcp6       0      0 :::8388                 :::*                    LISTEN      4238/docker-proxy
  </code></pre>
  
  <p>I really can't find the reason, thank you for your help.</p>