-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
33 lines (33 loc) · 685 Bytes
/
process.py
File metadata and controls
33 lines (33 loc) · 685 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
31
32
33
def processIncomingData(path, reqdata):
url = path
if (url == "/"):
url = "index.html"
else:
pass
while (url[-1] == "/" and len(url) > 1):
url = url[:-1]
# print(url)
try:
f = open(url, "rb")
content = f.read()
except:
# print("Error")
content = ""
try:
ext = url.split('.')[-1]
except:
ext = ""
while (len(ext) > 1 and ext[-1] == '/'):
ext = ext[:-1]
mimetypes = {
"css": "text/css",
"html": "text/html",
"js": "application/javascript",
"jpg": "image/jpeg",
"png": "image/png",
"ico": "image/x-icon",
}
mimetype = mimetypes.get(ext, "text/html")
data = reqdata.decode("utf-8").split(" ")
# print(mimetype)
return content, mimetype, data