使用twisted和sockjs获取websocket请求的headervalue

2024-06-07 16:51:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个sockjs服务器在haproxy后面。现在我需要一个客户端的ip地址,但是使用self.transport.getPeer()我得到了我的haproxy的ip。Haproxy向请求添加了一个X-Forward-For头,其中包含原始客户端的ip。在

如何获取协议中已发送到服务器的原始http请求?在

class MyProtocol(LineReceiver):
    def connectionMade(self):
        # this next line only gives me the ip of my proxy
        ip = self.transport.getPeer()

class MyFactory(protocol.ServerFactory):
    protocol = MyProtocol

my_factory = MyFactory()
sockjs_factory = SockJSMultiFactory()
sockjs_factory.addFactory(my_factory, 'echo')

sockjs_service = internet.TCPServer(10000, sockjs_factory)

application = service.Application("frog32")
sockjs_service.setServiceParent(application)

Tags: selfip服务器客户端myfactoryserviceprotocol

热门问题