https服务搭建
主要参考资料:
https://juejin.cn/post/7011703754999201823

参考github 地址:
https://github.com/zer1t0/httpsweet

生成 证书和私钥
openssl genrsa -out test.key 2048
openssl req -new -x509 -days 3650 -key test.key -out test.crt
1
2
运行https 服务
环境: Python 3.8
下面命令可以重新编译

python3 setup.py install
1
下面命令可以启动https服务。

python3 httpsweet --bind {ip} --directory {directory} --cert {cert} --key {key} {port}
1
修改源码支持POST 请求下载文件
这个服务器写的比较简洁,看下代码, 修改下相关逻辑即可支持post 请求下载文件。

修改的文件名称:
parameters.py
原函数为 POST请求直接上传动作, 把逻辑修改一下:
修改前:

@classmethod
def from_method(cls, method):
    if method == "POST" or method == "PUT":
        return cls(action=Action.UPLOAD)
    else:
        return cls(action=Action.DOWNLOAD)

1
2
3
4
5
6
修改后:

@classmethod
def from_method(cls, method):
    if method == "PUT":
        return cls(action=Action.UPLOAD)
    else:
        return cls(action=Action.DOWNLOAD)

修改源码后记得重新编译,再运行

python3 setup.py install

总结
这个项目比较简单, 可以阅读学习源码,并根据自己的需求做相应修改进行使用。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐