ENTERPRISE file extensions (#941 omake);

in case a snakeoil salesman managed to convince your workplace into
purchasing their "internet security solution" which blocks downloads
of certain files according to file extensions -- or, in other words,
smoke and mirrors, with a comforting false sense of security
This commit is contained in:
ed
2025-10-22 22:10:02 +00:00
parent c9e45c12d8
commit b624a38747
8 changed files with 41 additions and 14 deletions

View File

@@ -30,7 +30,7 @@ try:
except:
pass
from .__init__ import ANYWIN, RES, TYPE_CHECKING, EnvParams, unicode
from .__init__ import ANYWIN, RES, RESM, TYPE_CHECKING, EnvParams, unicode
from .__version__ import S_VERSION
from .authsrv import LEELOO_DALLAS, VFS # typechk
from .bos import bos
@@ -1275,6 +1275,20 @@ class HttpCli(object):
else:
return self.tx_res(res_path)
if res_path in RESM:
ap = self.E.mod_ + RESM[res_path]
if (
"txt" not in self.uparam
and "mime" not in self.uparam
and not self.ouparam.get("dl")
):
# return mimetype matching request extension
self.ouparam["dl"] = res_path.split("/")[-1]
if bos.path.exists(ap) or bos.path.exists(ap + ".gz"):
return self.tx_file(ap)
else:
return self.tx_res(res_path)
self.tx_404()
return False
@@ -4179,8 +4193,11 @@ class HttpCli(object):
# force download
if "dl" in self.ouparam:
cdis = gen_content_disposition(os.path.basename(req_path))
self.out_headers["Content-Disposition"] = cdis
cdis = self.ouparam["dl"] or req_path
zs = gen_content_disposition(os.path.basename(cdis))
self.out_headers["Content-Disposition"] = zs
else:
cdis = req_path
#
# if-modified
@@ -4246,7 +4263,7 @@ class HttpCli(object):
elif "mime" in self.uparam:
mime = str(self.uparam.get("mime"))
else:
mime = guess_mime(req_path)
mime = guess_mime(cdis)
logmsg += unicode(status) + logtail
@@ -4354,8 +4371,11 @@ class HttpCli(object):
# force download
if "dl" in self.ouparam:
cdis = gen_content_disposition(os.path.basename(req_path))
self.out_headers["Content-Disposition"] = cdis
cdis = self.ouparam["dl"] or req_path
zs = gen_content_disposition(os.path.basename(cdis))
self.out_headers["Content-Disposition"] = zs
else:
cdis = req_path
#
# if-modified
@@ -4483,7 +4503,7 @@ class HttpCli(object):
elif "rmagic" in self.vn.flags:
mime = guess_mime(req_path, fs_path)
else:
mime = guess_mime(req_path)
mime = guess_mime(cdis)
if "nohtml" in self.vn.flags and "html" in mime:
mime = "text/plain; charset=utf-8"