Python 3 http 服务器在同一端口上托管多个 Windows 驱动器
我知道您可以通过 Python 3 创建服务器
def run(server_class=ThreadingHTTPServer, handler_class=CustomHandler):
server_address = ('', 8000)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
,您甚至可以在 CustomHandler
构造函数中指定自定义位置来保存文件,无论脚本从何处运行,例如
class CustomHandler(SimpleHTTPRequestHandler):
def __init__(self, *args, dir='D://'):
super().__init__(*args, directory=dir)
问题:
我想知道是否有办法将 PC 中的所有驱动器托管在同一服务器的端口上。
我知道应该使用 nginx 或 apache 来完成这些事情,但我正在寻找纯 python 解决方案,因为我正在重写大部分 http.server
方法来根据我的需要构建具有某些特定行为的服务器。
任何线索将不胜感激。
I know you can create servers in Python 3 through
def run(server_class=ThreadingHTTPServer, handler_class=CustomHandler):
server_address = ('', 8000)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
And you can even specify custom location in CustomHandler
constructor to hold file despite whereever the script is ran from like
class CustomHandler(SimpleHTTPRequestHandler):
def __init__(self, *args, dir='D://'):
super().__init__(*args, directory=dir)
Question:
I was wondering if there is a way to host all drives in the PC on same server's port.
I know one should use nginx or apache for such things but I am looking for pure python only solution, because I am rewriting most of http.server
methods to build a server with some specific behaviour as per my needs.
Any clues would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论