-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
68 lines (63 loc) · 2.29 KB
/
server.py
File metadata and controls
68 lines (63 loc) · 2.29 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from http.server import BaseHTTPRequestHandler,HTTPServer
import json, os, parser
PORT_NUMBER = 5000
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/' or self.path == "":
self.path = "/index.html"
try:
sendReply = False
if self.path.endswith(".html"):
mimetype = "text/html"
sendReply = True
if self.path.endswith(".json"):
mimetype = "text/plain"
sendReply = True
if self.path.endswith(".js"):
mimetype = "application/javascript"
sendReply = True
if self.path.endswith(".png"):
mimetype = "image/png"
sendReply = True
if self.path.endswith(".css"):
mimetype = "text/css"
sendReply = True
if self.path.endswith(".ico"):
mimetype = "image/icon"
sendReply = True
if self.path.endswith(".svg"):
mimetype = "image/svg+xml"
sendReply = True
if self.path.endswith(".glsl"):
mimetype = "text/palin"
sendReply = True
if self.path.endswith(".obj"):
mimetype = "text/plain"
sendReply = True
if self.path.endswith(".mtl"):
mimetype = "text/plain"
sendReply = True
if self.path.endswith(".jpg"):
mimetype = "image/jpg"
sendReply = True
if sendReply:
f = open("." + self.path, "rb")
self.send_response(200)
self.send_header("Content-type", mimetype)
self.end_headers()
self.wfile.write(f.read())
f.close()
return
except IOError:
self.send_error(404, "File Not Found: " + self.path)
def do_POST(self):
mesh = parser.parseOBJ(self.path[1:])
self.send_response(200)
self.send_header("Cantent-type", "text/plain")
self.end_headers()
self.wfile.write(bytes(json.dumps(mesh), "utf-8"))
try:
server = HTTPServer(("", PORT_NUMBER), Handler)
server.serve_forever()
except KeyboardInterrupt:
server.socket.close()