from twisted.internet import protocol, reactor, endpoints
class Server(protocol.Protocol):
def connectionLost(self, *args):
print('Connection lost')
def dataReceived(self, data):
self.transport.write(data)
class buildFactory(protocol.Factory):
def buildProtocol(self, addr):
return Server()
if __name__ == '__main__':
reactor.listenTCP(8000, buildFactory())
reactor.run()
如何设置和获取服务器/客户端标头?
我已经搜索了所有搜索结果,但我发现的答案要求您创建一个http服务器。
答案 0 :(得分:0)
此处的文件:
https://twistedmatrix.com/documents/8.0.0/api/twisted.web.http.Request.html
您正在寻找特定的getHeader部分
https://twistedmatrix.com/documents/8.0.0/api/twisted.web.http.Request.html#getHeader
def getAllHeaders(self): (source)
Return dictionary of all headers the request received.