Tornado HTTP 代理服务器未捕获 HTTPS 请求

Tornado HTTP proxy server not catching HTTPS request

我已经设置了一个用作代理服务器的 tornado HTTP 服务器。 我正在使用 python 请求库将其用作代理服务器。 当我尝试用它获取 HTTP url 时,它工作正常。但它不会拦截 HTTPS 请求。

代理服务器部分:

class ProxyServer(HTTPServerConnectionDelegate):
    def start_request(self, server_conn, request_conn):
        print('In start request')
        return ClientDelegator(request_conn)

    def on_close(self):
        pass

    def client_send_error(self):
        self.write('Error happened.')
        self.finish()


def main():
    server = HTTPServer(ProxyServer())
    server.bind(8888)
    server.start(0)
    tornado.ioloop.IOLoop.current().start()


if __name__ == "__main__":
    main()

请求部分:

import requests


url = 'https://example.com'
proxy = {'http' : '127.0.0.1:8888'}
r = requests.get(url, proxies=proxy, verify=False)
print(r.text)

当我使用 http://example.com, the connection starts as 'In start request' gets printed. However, when I use https://example.com 时,连接无法启动。 ProxyServer 没有进入 start_request.

我做错了什么?

您的 proxy 变量仅指定 http 的代理,而不是 https。您需要分别为这两种协议设置代理。