【发布时间】:2023-09-11 19:29:01
【问题描述】:
我会尽力解释一切,服务器的新手!一切都在 Go 中,主要问题在于 ServeHTTP。
问题
我正在处理将(http.server).ListenAndServe() 收到的请求转发到通过(http.ReverseProxy).ServeHTTP(http.ResponseWriter, *http.Request) 发送到另一个代理服务器。我正在使用 python 请求提交 GET 请求并通过第一台服务器和第二台服务器将其代理到实际目标。我已经能够提交和接收http请求,但是我不能提交https请求。
错误
当我使用 https://httpbin.org 或任何其他 https 站点时,我经常从 python 请求库收到 502 bad gateway,这可能是来自 ServeHTTP() 的 http: proxy error: unsupported protocol scheme "" 的结果。使用 http 会导致 html 返回给我。
反应差异
*http.Response 中的区别在于 http 是
&{GET http://httpbin.org HTTP/1.0 1 0 map[] <nil> <nil> 0 [] true http://httpbin.org map[] map[] <nil> map[] [my ip address] http://httpbin.org <nil> <nil> <nil> 0xc000050fc0}
而https是
&{CONNECT //httpbin.org:443 HTTP/1.0 1 0 map[] <nil> <nil> 0 [] true httpbin.org:443 map[] map[] <nil> map[] [my ip address] httpbin.org:443 <nil> <nil> <nil> 0xc0000503c0}
这是 *http.Request 文档的link
我之前尝试过的
我尝试修改 ReverseProxy.Director 属性并让函数修改 *http.Request。我已经完成了从删除“:443”到添加“https://”甚至“http://”的所有工作。这样做会导致错误的请求错误。我还尝试将 CONNECT 请求更改为 GET 或 POST,这两种方法都有奇怪的结果,包括无效的方法或错误的请求。
有什么帮助吗?
【问题讨论】:
-
基础错误是
unsupported protocol scheme "",这意味着 URL 的方案部分(例如 http、https)不存在。在您的情况下,HTTPS 案例的 *http.Request 在 URL 开头缺少“https:”://httpbin.org:443,但您需要https://httpbin.org:443。你能分享你用来创建 HTTPS 请求的代码吗?