forked from tongyy/python-httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPS_Server.py
More file actions
28 lines (22 loc) · 792 Bytes
/
HTTPS_Server.py
File metadata and controls
28 lines (22 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import BaseHTTPServer,SimpleHTTPServer,SocketServer
import cgi
import sys
import socket
import ssl
PORT = int(sys.argv[1])
def staticHttpServer(req):
print(req.headers)
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(req)
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
staticHttpServer(self)
def do_POST(self):
body = self.rfile.read(int(self.headers['Content-Length']))
print(body)
staticHttpServer(self)
Handler = ServerHandler
httpd = BaseHTTPServer.HTTPServer(("", PORT),Handler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='../cert.pem', server_side=True)
ip = "127.0.0.1"
print "Serving at: https://%(interface)s:%(port)s" % dict(interface=ip or "localhost", port=PORT)
httpd.serve_forever()