python http 处理程序
我想要类似 BaseHTTPRequestHandler
的东西,除了我不希望它绑定到任何套接字;我想自己处理传入和传出的原始 HTTP 数据。有没有什么好的方法可以让我在 Python 中做到这一点?
为了澄清,我想要一个从Python(不是套接字)接收原始TCP数据的类,处理它并返回TCP数据作为响应(再次返回到python)。因此,此类将处理 TCP 握手,并且将具有覆盖我在 HTTP GET 和 POST 上发送的内容的方法,例如 do_GET
和 do_POST
。因此,我想要类似已经存在的服务器基础设施的东西,但我想在 python 中传递所有原始 TCP 数据包,而不是通过操作系统套接字。
I want something like BaseHTTPRequestHandler
, except that I don't want it to bind to any sockets; I want to handle the raw HTTP data to and from it myself. Is there a good way that I can do this in Python?
To Clarify, I want a class that receives raw TCP data from Python (NOT a socket), processes it and returns TCP data as a response (to python again). So this class will handle TCP handshaking, and will have methods that override what I send on HTTP GET and POST, like do_GET
and do_POST
. So, I want something like the Server infrastructure that already exists, except I want to pass all raw TCP packets in python and not through operating system sockets.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
BaseHTTPRequestHandler
派生自StreamRequestHandler
,它基本上从文件self.rfile
读取并写入self.wfile
,因此您可以从BaseHTTPRequestHandler
派生一个类并提供您自己的rfile和wfile,例如输出:
BaseHTTPRequestHandler
derives fromStreamRequestHandler
, which basically reads from fileself.rfile
and writes toself.wfile
, so you can derive a class fromBaseHTTPRequestHandler
and supply your own rfile and wfile e.g.Output: