<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 (
"log"
"net/http"
"net/http/httputil"
)
func Proxy() *httputil.ReverseProxy {
director := func(req *http.Request) {}
return &httputil.ReverseProxy {Director: director}
}
func Handler(rw http.ResponseWriter, req *http.Request) {
Proxy().ServeHTTP(rw, req)
}
func main() {
http.HandleFunc("/", Handler)
// start http proxy
go func() {
err := http.ListenAndServe(":8000", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}()
// start https proxy
err := http.ListenAndServeTLS(":8001", "cert.pem", "key.pem", nil)
if err != nil {
log.Fatal("ListenAndServe: ", 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
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传