Python 3 http 服务器在同一端口上托管多个 Windows 驱动器

发布于 2025-01-20 15:31:09 字数 683 浏览 3 评论 0原文

我知道您可以通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文