https issue with very simple proxy. Any help/suggestion is appreciated.

agolangf · · 564 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I am writing a http and https proxy, attempting to keep the code as short and simple as possible. The http proxy works however the https proxy does not.</p> <p>Executing:</p> <pre><code>curl -k -x https://localhost:8001 https://google.com </code></pre> <p>results in the following slightly confusing error:</p> <pre><code>2016/02/01 00:34:34 http: TLS handshake error from [::1]:49951: tls: oversized record received with length 20037 </code></pre> <p>.</p> <pre><code>package main import ( &#34;log&#34; &#34;net/http&#34; &#34;net/http/httputil&#34; ) func Proxy() *httputil.ReverseProxy { director := func(req *http.Request) {} return &amp;httputil.ReverseProxy {Director: director} } func Handler(rw http.ResponseWriter, req *http.Request) { Proxy().ServeHTTP(rw, req) } func main() { http.HandleFunc(&#34;/&#34;, Handler) // start http proxy go func() { err := http.ListenAndServe(&#34;:8000&#34;, nil) if err != nil { log.Fatal(&#34;ListenAndServe: &#34;, err) } }() // start https proxy err := http.ListenAndServeTLS(&#34;:8001&#34;, &#34;cert.pem&#34;, &#34;key.pem&#34;, nil) if err != nil { log.Fatal(&#34;ListenAndServe: &#34;, err) } } </code></pre> <hr/>**评论:**<br/><br/>nhooyr: <pre><p>Curl is treating it as a HTTP proxy. In order to verify try this.</p> <pre><code>nc -l localhost 8001 </code></pre> <p>Then run the curl command and look at the output. plain http.</p> <p>This is intended, take a look at the following.</p> <p><a href="http://stackoverflow.com/questions/516323/https-connections-over-proxy-servers" rel="nofollow">http://stackoverflow.com/questions/516323/https-connections-over-proxy-servers</a></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

564 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传