-
Notifications
You must be signed in to change notification settings - Fork 0
/
pythonSprinklerServer.py
42 lines (33 loc) · 1.1 KB
/
pythonSprinklerServer.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import SocketServer
class S(BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_GET(self):
self._set_headers()
self.wfile.write("GET REQUEST")
def do_HEAD(self):
self._set_headers()
def do_POST(self):
# Doesn't do anything with posted data
self._set_headers()
print "POST"
request = self.rfile.read(int(self.headers.getheader('content-length')))
handleRequest(request)
self.wfile.write("POST REQUEST\n")
def run(server_class=HTTPServer, handler_class=S, port=8123):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print 'Starting httpd...'
httpd.serve_forever()
def handleRequest(request):
print "Got request - \n" + request
#Implement function here
if __name__ == "__main__":
from sys import argv
if len(argv) == 2:
run(port=int(argv[1]))
else:
run()