-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
30 lines (24 loc) · 840 Bytes
/
Copy pathmain.py
File metadata and controls
30 lines (24 loc) · 840 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
29
30
# Python 3 server example
from http.server import BaseHTTPRequestHandler, HTTPServer
import json
hostName = "0.0.0.0"
serverPort = 8000
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
headers = {}
for h in self.headers:
headers[h] = self.headers[h]
self.send_response(200)
self.send_header("Content-type", "application/json")
self.send_header("ALL_CAPS_RESPONSE_HEADER", "grep_me")
self.end_headers()
self.wfile.write(bytes(json.dumps(headers), "utf-8"))
if __name__ == "__main__":
webServer = HTTPServer((hostName, serverPort), MyServer)
print("Server started http://%s:%s" % (hostName, serverPort))
try:
webServer.serve_forever()
except KeyboardInterrupt:
pass
webServer.server_close()
print("Server stopped.")