forked from tongyy/python-httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTP_Server.py
More file actions
27 lines (21 loc) · 688 Bytes
/
HTTP_Server.py
File metadata and controls
27 lines (21 loc) · 688 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
import SimpleHTTPServer
import SocketServer
import cgi
import sys
import socket
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 = SocketServer.TCPServer(("", PORT), Handler)
ip = "127.0.0.1"
print "Serving at: http://%(interface)s:%(port)s" % dict(interface=ip or "localhost", port=PORT)
httpd.serve_forever()