mininet-sample/utils/http_server.py

36 lines
920 B
Python
Raw Normal View History

2015-12-01 16:48:32 +00:00
'''
From :
http://code.activestate.com/recipes/442473-simple-http-server-supporting-ssl-secure-communica/
SimpleHTTPServer.py - simple HTTP server supporting SSL.
- the default port is 80.
usage: python SimpleHTTPServer.py
'''
import socket, os
2020-06-24 14:11:54 +00:00
try:
# Python 2
from SocketServer import BaseServer
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
except ImportError:
# Python 3
from socketserver import BaseServer
from http.server import HTTPServer, SimpleHTTPRequestHandler
2015-12-01 16:48:32 +00:00
2020-06-24 14:11:54 +00:00
from OpenSSL import SSL
2015-12-01 16:48:32 +00:00
def test(HandlerClass=SimpleHTTPRequestHandler,
ServerClass=HTTPServer):
server_address = ('', 80) # (address, port)
httpd = ServerClass(server_address, HandlerClass)
sa = httpd.socket.getsockname()
2020-06-24 14:11:54 +00:00
print("Serving HTTP on", sa[0], "port", sa[1], "...")
2015-12-01 16:48:32 +00:00
httpd.serve_forever()
if __name__ == '__main__':
test()