3 Star 0 Fork 0

mirrors_zephyrproject-rtos/net-tools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
https-server.py 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/python
# HTTPS server test application.
#
# You can generate certificate file like this:
# openssl req -x509 -newkey rsa:2048 -keyout https-server.pem \
# -out https-server.pem -days 10000 -nodes \
# -subj '/CN=localhost'
#
# To see the contents of the certificate do this:
# openssl x509 -in https-server.pem -text -noout
#
# To add the cert into your application do this:
# openssl x509 -in https-server.pem -C -noout
#
import socket
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
import ssl
PORT = 4443
class HTTPServerV6(HTTPServer):
address_family = socket.AF_INET6
class RequestHandler(SimpleHTTPRequestHandler):
length = 0
def _set_headers(self):
self.send_response(200)
self.send_header('Content-Type', 'text/html')
self.send_header('Content-Length', str(self.length))
self.end_headers()
def do_POST(self):
payload = "<html><p>Done</p></html>"
self.length = len(payload)
self._set_headers()
self.wfile.write(payload)
def main():
httpd = HTTPServerV6(("", PORT), RequestHandler)
print "Serving at port", PORT
httpd.socket = ssl.wrap_socket(httpd.socket,
certfile='./https-server.pem',
server_side=True)
httpd.serve_forever()
if __name__ == '__main__':
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_zephyrproject-rtos/net-tools.git
git@gitee.com:mirrors_zephyrproject-rtos/net-tools.git
mirrors_zephyrproject-rtos
net-tools
net-tools
master

搜索帮助