|
|
|
@ -26,6 +26,9 @@ global gSettingsDict
|
|
|
|
|
from . import ServerSettings
|
|
|
|
|
from . import __Orchestrator__
|
|
|
|
|
import copy
|
|
|
|
|
import mimetypes
|
|
|
|
|
|
|
|
|
|
gCacheDict = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Tool to merge complex dictionaries
|
|
|
|
@ -266,6 +269,8 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
#Tech sub def - do item
|
|
|
|
|
################################
|
|
|
|
|
def URLItemDo(inURLItem,inRequest,inGlobalDict):
|
|
|
|
|
global gCacheDict
|
|
|
|
|
inResponseDict["Headers"]["Content-type"]= None
|
|
|
|
|
inResponseDict = inRequest.OpenRPAResponseDict
|
|
|
|
|
#Set status code 200
|
|
|
|
|
inResponseDict["StatusCode"] = 200
|
|
|
|
@ -274,11 +279,27 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
inResponseDict["Headers"]["Content-type"] = inURLItem["ResponseContentType"]
|
|
|
|
|
#If file path is set
|
|
|
|
|
if "ResponseFilePath" in inURLItem:
|
|
|
|
|
lFileObject = open(inURLItem["ResponseFilePath"], "rb")
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
inResponseDict["Body"] = lFileObject.read()
|
|
|
|
|
# Закрыть файловый объект
|
|
|
|
|
lFileObject.close()
|
|
|
|
|
# Check cache
|
|
|
|
|
if inURLItem.get("inUseCacheBool",False) == True:
|
|
|
|
|
if inURLItem["ResponseFilePath"] in gCacheDict:
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
inResponseDict["Body"] = gCacheDict[inURLItem["ResponseFilePath"]]
|
|
|
|
|
else:
|
|
|
|
|
lFileObject = open(inURLItem["ResponseFilePath"], "rb")
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
gCacheDict[inURLItem["ResponseFilePath"]] = lFileObject.read()
|
|
|
|
|
inResponseDict["Body"] = gCacheDict[inURLItem["ResponseFilePath"]]
|
|
|
|
|
# Закрыть файловый объект
|
|
|
|
|
lFileObject.close()
|
|
|
|
|
else:
|
|
|
|
|
lFileObject = open(inURLItem["ResponseFilePath"], "rb")
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
inResponseDict["Body"] = lFileObject.read()
|
|
|
|
|
# Закрыть файловый объект
|
|
|
|
|
lFileObject.close()
|
|
|
|
|
# detect MIME type if none
|
|
|
|
|
if inResponseDict["Headers"]["Content-type"] is None:
|
|
|
|
|
inResponseDict["Headers"]["Content-type"]= mimetypes.guess_type(inURLItem["ResponseFilePath"])[0]
|
|
|
|
|
#If function is set
|
|
|
|
|
if "ResponseDefRequestGlobal" in inURLItem:
|
|
|
|
|
lDef = inURLItem["ResponseDefRequestGlobal"]
|
|
|
|
@ -290,6 +311,7 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
else:
|
|
|
|
|
inURLItem["ResponseDefRequestGlobal"]()
|
|
|
|
|
if "ResponseFolderPath" in inURLItem:
|
|
|
|
|
|
|
|
|
|
#lRequestPath = inRequest.path
|
|
|
|
|
lRequestPath = urllib.parse.unquote(inRequest.path)
|
|
|
|
|
if inURLItem["URL"][-1]!="/": inURLItem["URL"]+= "/" # Fix for settings
|
|
|
|
@ -298,12 +320,30 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
#print(f"File full path {lFilePath}")
|
|
|
|
|
#Check if file exist
|
|
|
|
|
if os.path.exists(lFilePath) and os.path.isfile(lFilePath):
|
|
|
|
|
lFileObject = open(lFilePath, "rb")
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
inResponseDict["Body"] = lFileObject.read()
|
|
|
|
|
inResponseDict["ContentType"]= "application/octet-stream"
|
|
|
|
|
# Закрыть файловый объект
|
|
|
|
|
lFileObject.close()
|
|
|
|
|
# Check cache
|
|
|
|
|
if inURLItem.get("inUseCacheBool",False) == True:
|
|
|
|
|
if lFilePath in gCacheDict:
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
inResponseDict["Body"] = gCacheDict[lFilePath]
|
|
|
|
|
else:
|
|
|
|
|
lFileObject = open(lFilePath, "rb")
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
gCacheDict[lFilePath] = lFileObject.read()
|
|
|
|
|
inResponseDict["Body"] = gCacheDict[lFilePath]
|
|
|
|
|
# Закрыть файловый объект
|
|
|
|
|
lFileObject.close()
|
|
|
|
|
else:
|
|
|
|
|
lFileObject = open(lFilePath, "rb")
|
|
|
|
|
# Write content as utf-8 data
|
|
|
|
|
inResponseDict["Body"] = lFileObject.read()
|
|
|
|
|
# Закрыть файловый объект
|
|
|
|
|
lFileObject.close()
|
|
|
|
|
# detect MIME type if none
|
|
|
|
|
if inResponseDict["Headers"]["Content-type"] is None:
|
|
|
|
|
inResponseDict["Headers"]["Content-type"]= mimetypes.guess_type(lFilePath)[0]
|
|
|
|
|
# If No content-type
|
|
|
|
|
if inResponseDict["Headers"]["Content-type"] is None:
|
|
|
|
|
inResponseDict["Headers"]["Content-type"]= "application/octet-stream"
|
|
|
|
|
##############################################
|
|
|
|
|
# UAC Check
|
|
|
|
|
if inOnlyFlagUACBool == True and inURLItem.get("UACBool",None) in [None, True]:
|
|
|
|
|