Add support for keep-alive (Doesn't work right now, idk why)
This commit is contained in:
parent
d5664f33e1
commit
1b36386eae
@ -114,6 +114,9 @@ def simpleResponse(connection,status,headers = None,content = None,autolength =
|
|||||||
if content != None and autolength == True:
|
if content != None and autolength == True:
|
||||||
headers["Content-Length"] = str(len(content))
|
headers["Content-Length"] = str(len(content))
|
||||||
|
|
||||||
|
if allowKeepAlive and not ("Connection" in headers):
|
||||||
|
headers["Connection"] = "keep-alive"
|
||||||
|
headers["Keep-Alive"] = "timeout=" +str(timeout)
|
||||||
response = 'HTTP/1.1 ' +status+ '\r\n'
|
response = 'HTTP/1.1 ' +status+ '\r\n'
|
||||||
for header in headers:
|
for header in headers:
|
||||||
response += header + ": " +headers[header] + "\r\n"
|
response += header + ": " +headers[header] + "\r\n"
|
||||||
|
@ -12,74 +12,79 @@ pathHandlers = {}
|
|||||||
|
|
||||||
global clientLoopIn
|
global clientLoopIn
|
||||||
def clientLoopIn(self):
|
def clientLoopIn(self):
|
||||||
env = {}
|
while True:
|
||||||
env["self"] = self
|
env = {}
|
||||||
env["requestTime"] = time.time()
|
env["self"] = self
|
||||||
env["header"] = getHeaderFromConnection(self.connection)
|
env["requestTime"] = time.time()
|
||||||
env["protocolHeaderList"],env["headerList"] = parseHeader(env["header"])
|
env["header"] = getHeaderFromConnection(self.connection)
|
||||||
env["cmd"] = env["protocolHeaderList"][0]
|
env["protocolHeaderList"],env["headerList"] = parseHeader(env["header"])
|
||||||
env["path"],env["args"] = parseHeaderPath(env["protocolHeaderList"][1])
|
env["cmd"] = env["protocolHeaderList"][0]
|
||||||
env["pathFixed"] = fixUserPath(env["path"])
|
env["path"],env["args"] = parseHeaderPath(env["protocolHeaderList"][1])
|
||||||
|
env["pathFixed"] = fixUserPath(env["path"])
|
||||||
|
|
||||||
env["lPath"] = env["pathFixed"].replace("/",os.path.sep)
|
env["lPath"] = env["pathFixed"].replace("/",os.path.sep)
|
||||||
env["fPath"] = p(indexPath,env["lPath"])
|
env["fPath"] = p(indexPath,env["lPath"])
|
||||||
env["fileExt"] = "."
|
env["fileExt"] = "."
|
||||||
|
|
||||||
if not env["pathFixed"] == "" and not os.path.isfile(env["fPath"]) and os.path.isdir(env["fPath"]) and env["pathFixed"][-1] != "/": env["pathFixed"] += "/" # This is dirty, since it possibly circumvents .fhtpyaccess (You can see if a folder exists or not by probing)
|
if not env["pathFixed"] == "" and not os.path.isfile(env["fPath"]) and os.path.isdir(env["fPath"]) and env["pathFixed"][-1] != "/": env["pathFixed"] += "/" # This is dirty, since it possibly circumvents .fhtpyaccess (You can see if a folder exists or not by probing)
|
||||||
|
|
||||||
if "/" + env["pathFixed"] != env["path"]:
|
if "/" + env["pathFixed"] != env["path"]:
|
||||||
newPath = "/" + pathToURL(env["pathFixed"])
|
newPath = "/" + pathToURL(env["pathFixed"])
|
||||||
rawArgs = env["protocolHeaderList"][1].split("?",1)
|
rawArgs = env["protocolHeaderList"][1].split("?",1)
|
||||||
|
|
||||||
if len(rawArgs) > 1:
|
if len(rawArgs) > 1:
|
||||||
newPath += "?" +rawArgs[-1]
|
newPath += "?" +rawArgs[-1]
|
||||||
|
|
||||||
refer(self.connection,newPath)
|
refer(self.connection,newPath)
|
||||||
return
|
|
||||||
|
|
||||||
if env["pathFixed"] in pathHandlers:
|
|
||||||
pathHandlers[env["pathFixed"]](env)
|
|
||||||
return
|
|
||||||
|
|
||||||
if not os.path.isfile(env["fPath"]):
|
|
||||||
if not os.path.isdir(env["fPath"]):
|
|
||||||
handle404(env)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
found = False
|
if env["pathFixed"] in pathHandlers:
|
||||||
for file in indexFiles:
|
pathHandlers[env["pathFixed"]](env)
|
||||||
if os.path.isfile(p(env["fPath"],file)):
|
return
|
||||||
found = file
|
|
||||||
break
|
|
||||||
|
|
||||||
if found == False:
|
if not os.path.isfile(env["fPath"]):
|
||||||
env["fileExt"] = ".d"
|
if not os.path.isdir(env["fPath"]):
|
||||||
env["lPath"] = p(env["lPath"],".")
|
handle404(env)
|
||||||
env["fPath"] = p(indexPath,env["lPath"])
|
return
|
||||||
|
|
||||||
|
found = False
|
||||||
|
for file in indexFiles:
|
||||||
|
if os.path.isfile(p(env["fPath"],file)):
|
||||||
|
found = file
|
||||||
|
break
|
||||||
|
|
||||||
|
if found == False:
|
||||||
|
env["fileExt"] = ".d"
|
||||||
|
env["lPath"] = p(env["lPath"],".")
|
||||||
|
env["fPath"] = p(indexPath,env["lPath"])
|
||||||
|
else:
|
||||||
|
env["lPath"] = p(env["lPath"],found)
|
||||||
|
env["fPath"] = p(indexPath,env["lPath"])
|
||||||
|
lPathSplit = env["lPath"].rsplit(os.path.sep,1)[-1].rsplit(".",1)
|
||||||
|
if len(lPathSplit) > 1:
|
||||||
|
env["fileExt"] = lPathSplit[-1].lower()
|
||||||
else:
|
else:
|
||||||
env["lPath"] = p(env["lPath"],found)
|
|
||||||
env["fPath"] = p(indexPath,env["lPath"])
|
|
||||||
lPathSplit = env["lPath"].rsplit(os.path.sep,1)[-1].rsplit(".",1)
|
lPathSplit = env["lPath"].rsplit(os.path.sep,1)[-1].rsplit(".",1)
|
||||||
if len(lPathSplit) > 1:
|
if len(lPathSplit) > 1:
|
||||||
env["fileExt"] = lPathSplit[-1].lower()
|
env["fileExt"] = lPathSplit[-1].lower()
|
||||||
else:
|
|
||||||
lPathSplit = env["lPath"].rsplit(os.path.sep,1)[-1].rsplit(".",1)
|
|
||||||
if len(lPathSplit) > 1:
|
|
||||||
env["fileExt"] = lPathSplit[-1].lower()
|
|
||||||
|
|
||||||
env["fPathDir"] = pUp(env["fPath"])
|
env["fPathDir"] = pUp(env["fPath"])
|
||||||
env["requestTimeFormatted"] = email.utils.formatdate(int(env["requestTime"])).replace("-0000","GMT")
|
env["requestTimeFormatted"] = email.utils.formatdate(int(env["requestTime"])).replace("-0000","GMT")
|
||||||
|
|
||||||
env["handler"] = False
|
env["handler"] = False
|
||||||
if env["fileExt"] in fileHandlers:
|
if env["fileExt"] in fileHandlers:
|
||||||
env["handler"] = fileHandlers[env["fileExt"]]
|
env["handler"] = fileHandlers[env["fileExt"]]
|
||||||
elif ".*" in fileHandlers:
|
elif ".*" in fileHandlers:
|
||||||
env["handler"] = fileHandlers[".*"]
|
env["handler"] = fileHandlers[".*"]
|
||||||
|
|
||||||
if triggerEvent("handleHTTP",env) == False: return
|
if triggerEvent("handleHTTP",env) == False: return
|
||||||
|
|
||||||
if env["handler"]:
|
if env["handler"]:
|
||||||
env["handler"](env)
|
env["handler"](env)
|
||||||
else:
|
else:
|
||||||
handle404(env)
|
handle404(env)
|
||||||
return
|
|
||||||
|
if allowKeepAlive:
|
||||||
|
if "connection" in env["headerList"] and env["headerList"]["connection"] == "keep-alive":
|
||||||
|
continue
|
||||||
|
break
|
@ -4,3 +4,5 @@ global indexPath
|
|||||||
indexPath = p(sp,"index")
|
indexPath = p(sp,"index")
|
||||||
global readBufferSize
|
global readBufferSize
|
||||||
readBufferSize = 32768
|
readBufferSize = 32768
|
||||||
|
global allowKeepAlive
|
||||||
|
allowKeepAlive = False
|
Loading…
Reference in New Issue
Block a user