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