下面是我用来重定向端口8080上的常规HTTP请求的简单脚本,它立即根据源IP地址重定向(至少使它们成为)它们。在
它可以工作(对于HTTP),但是我希望对通过443端口发送的HTTPS请求有相同的行为。假设如果重定向不存在,则此简单服务器的传入客户端将能够通过自签名证书与重定向到的目标进行握手。在import SimpleHTTPServer
import SocketServer
LISTEN_PORT = 8080
source = "127.0.0.1"
target = "http://target/"
class simpleHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_POST(self):
clientAddressString = ''.join(str(self.clientAddress))
if source in clientAddressString:
# redirect incoming request
self.send_response(301)
new_path = '%s%s' % (target, self.path)
self.send_header('Location', new_path)
self.end_headers()
handler = SocketServer.TCPServer(("", LISTEN_PORT), simpleHandler)
handler.serve_forever()
我可以使用自签名证书并可以访问文件“服务器.crt“和”服务器.key“通常用于此连接(没有中间重定向python服务器)。我不确定当我像这样将重定向放在中间时会发生什么,尽管我认为它必须是握手链的一部分。在
我怎样才能达到这种行为?在
除了新目标和请求头中的响应代码之外,还有什么需要修改的吗?在