optimize connection:close

This commit is contained in:
ed
2026-03-21 19:47:44 +00:00
parent 1afe48b85d
commit bb92ce5fc8
6 changed files with 17 additions and 27 deletions

View File

@@ -228,7 +228,6 @@ class HttpCli(object):
self.args = conn.args # mypy404 self.args = conn.args # mypy404
self.E: EnvParams = self.args.E self.E: EnvParams = self.args.E
self.asrv = conn.asrv # mypy404 self.asrv = conn.asrv # mypy404
self.ico = conn.ico # mypy404
self.thumbcli = conn.hsrv.thumbcli self.thumbcli = conn.hsrv.thumbcli
self.u2fh = conn.u2fh # mypy404 self.u2fh = conn.u2fh # mypy404
self.pipes = conn.pipes # mypy404 self.pipes = conn.pipes # mypy404
@@ -534,7 +533,7 @@ class HttpCli(object):
else: else:
self.keepalive = False self.keepalive = False
ptn: Optional[Pattern[str]] = self.conn.lf_url # mypy404 ptn = self.conn.lf_url
self.do_log = not ptn or not ptn.search(self.req) self.do_log = not ptn or not ptn.search(self.req)
if self.args.ihead and self.do_log: if self.args.ihead and self.do_log:
@@ -5285,7 +5284,7 @@ class HttpCli(object):
# chrome cannot handle more than ~2000 unique SVGs # chrome cannot handle more than ~2000 unique SVGs
# so url-param "raster" returns a png/webp instead # so url-param "raster" returns a png/webp instead
# (useragent-sniffing kinshi due to caching proxies) # (useragent-sniffing kinshi due to caching proxies)
mime, ico = self.ico.get(txt, not small, "raster" in self.uparam) mime, ico = self.conn.hsrv.ico.get(txt, not small, "raster" in self.uparam)
lm = formatdate(self.E.t0) lm = formatdate(self.E.t0)
self.reply(ico, mime=mime, headers={"Last-Modified": lm}) self.reply(ico, mime=mime, headers={"Last-Modified": lm})

View File

@@ -21,10 +21,6 @@ from . import util as Util
from .__init__ import TYPE_CHECKING, EnvParams from .__init__ import TYPE_CHECKING, EnvParams
from .authsrv import AuthSrv # typechk from .authsrv import AuthSrv # typechk
from .httpcli import HttpCli from .httpcli import HttpCli
from .ico import Ico
from .mtag import HAVE_FFMPEG
from .th_cli import ThumbCli
from .th_srv import HAVE_PIL, HAVE_VIPS
from .u2idx import U2idx from .u2idx import U2idx
from .util import HMaccas, NetMap, shut_socket from .util import HMaccas, NetMap, shut_socket
@@ -69,19 +65,15 @@ class HttpConn(object):
self.bans: dict[str, int] = hsrv.bans self.bans: dict[str, int] = hsrv.bans
self.aclose: dict[str, int] = hsrv.aclose self.aclose: dict[str, int] = hsrv.aclose
self.ico: Ico = Ico(self.args) # mypy404
self.t0: float = time.time() # mypy404 self.t0: float = time.time() # mypy404
self.freshen_pwd: float = 0.0 self.freshen_pwd: float = 0.0
self.stopping = False self.stopping = False
self.nreq: int = -1 # mypy404 self.nreq: int = -1 # mypy404
self.nbyte: int = 0 # mypy404 self.nbyte: int = 0 # mypy404
self.u2idx: Optional[U2idx] = None self.u2idx: Optional[U2idx] = None
self.lf_url: Optional[Pattern[str]] = self.args.lf_url
self.log_func: "Util.RootLogger" = hsrv.log # mypy404 self.log_func: "Util.RootLogger" = hsrv.log # mypy404
self.log_src: str = "httpconn" # mypy404 self.log_src: str = "httpconn" # mypy404
self.lf_url: Optional[Pattern[str]] = (
re.compile(self.args.lf_url) if self.args.lf_url else None
) # mypy404
self.set_rproxy() self.set_rproxy()
def shutdown(self) -> None: def shutdown(self) -> None:

View File

@@ -56,6 +56,7 @@ except SyntaxError:
sys.exit(1) sys.exit(1)
from .httpconn import HttpConn from .httpconn import HttpConn
from .ico import Ico
from .metrics import Metrics from .metrics import Metrics
from .mtag import HAVE_FFMPEG from .mtag import HAVE_FFMPEG
from .th_cli import ThumbCli from .th_cli import ThumbCli
@@ -137,6 +138,7 @@ class HttpSrv(object):
self.aclose: dict[str, int] = {} self.aclose: dict[str, int] = {}
self.thumbcli: Optional[ThumbCli] = None self.thumbcli: Optional[ThumbCli] = None
self.ico: Ico = Ico(self.args)
dli: dict[str, tuple[float, int, "VFS", str, str]] = {} # info dli: dict[str, tuple[float, int, "VFS", str, str]] = {} # info
dls: dict[str, tuple[float, int]] = {} # state dls: dict[str, tuple[float, int]] = {} # state

View File

@@ -1145,7 +1145,7 @@ class SvcHub(object):
vsa = [x.upper() for x in vsa if x] vsa = [x.upper() for x in vsa if x]
setattr(al, k + "_set", set(vsa)) setattr(al, k + "_set", set(vsa))
zs = "dav_ua1 sus_urls nonsus_urls ua_nodav ua_nodoc ua_nozip" zs = "dav_ua1 lf_url sus_urls nonsus_urls ua_nodav ua_nodoc ua_nozip"
for k in zs.split(" "): for k in zs.split(" "):
vs = getattr(al, k) vs = getattr(al, k)
if not vs or vs == "no": if not vs or vs == "no":

View File

@@ -43,8 +43,8 @@ class ThumbCli(object):
# defer args.th_ff_jpg, can change at runtime # defer args.th_ff_jpg, can change at runtime
nonpil = next((x for x in self.args.th_dec if x in ("vips", "ff")), None) nonpil = next((x for x in self.args.th_dec if x in ("vips", "ff")), None)
self.can_webp = H_PIL_WEBP or nonpil self.can_webp = (H_PIL_WEBP or nonpil) and not self.args.th_no_webp
self.can_jxl = H_PIL_JXL or nonpil self.can_jxl = (H_PIL_JXL or nonpil) and not self.args.th_no_jxl
def log(self, msg: str, c: Union[int, str] = 0) -> None: def log(self, msg: str, c: Union[int, str] = 0) -> None:
self.log_func("thumbcli", msg, c) self.log_func("thumbcli", msg, c)
@@ -85,23 +85,20 @@ class ThumbCli(object):
if rem.startswith(".hist/th/") and rem.split(".")[-1] in IMG_EXTS: if rem.startswith(".hist/th/") and rem.split(".")[-1] in IMG_EXTS:
return os.path.join(ptop, rem) return os.path.join(ptop, rem)
if fmt[:1] in "jwx" and fmt != "wav": sfmt = fmt[:1]
sfmt = fmt[:1] if sfmt in "jwx" and fmt != "wav":
if sfmt == "j" and self.args.th_no_jpg: if sfmt == "j" and self.args.th_no_jpg:
sfmt = "w" sfmt = "w"
if sfmt == "w": if sfmt == "w":
if ( if not self.can_webp or (
self.args.th_no_webp self.args.th_ff_jpg and (not is_img or preferred == "ff")
or not self.can_webp
or (self.args.th_ff_jpg and (not is_img or preferred == "ff"))
): ):
sfmt = "j" sfmt = "j"
if sfmt == "x": if sfmt == "x" and not self.can_jxl:
if self.args.th_no_jxl or not self.can_jxl: sfmt = "w"
sfmt = "w"
vf_crop = dbv.flags["crop"] vf_crop = dbv.flags["crop"]
vf_th3x = dbv.flags["th3x"] vf_th3x = dbv.flags["th3x"]
@@ -118,7 +115,7 @@ class ThumbCli(object):
fmt = sfmt fmt = sfmt
elif fmt[:1] == "p" and not is_au and not is_vid: elif sfmt == "p" and not is_au and not is_vid:
t = "cannot thumbnail %r: png only allowed for waveforms" t = "cannot thumbnail %r: png only allowed for waveforms"
self.log(t % (rem,), 6) self.log(t % (rem,), 6)
return None return None

View File

@@ -149,7 +149,7 @@ class Cfg(Namespace):
ex = "dav_inf dedup dotpart dotsrch hook_v no_dhash no_fastboot no_fpool no_htp no_rescan no_sendfile no_ses no_snap no_up_list no_voldump wram re_dhash see_dots plain_ip" ex = "dav_inf dedup dotpart dotsrch hook_v no_dhash no_fastboot no_fpool no_htp no_rescan no_sendfile no_ses no_snap no_up_list no_voldump wram re_dhash see_dots plain_ip"
ka.update(**{k: True for k in ex.split()}) ka.update(**{k: True for k in ex.split()})
ex = "ah_cli ah_gen css_browser dbpath hist ipu js_browser js_other mime mimes no_forget no_hash no_idx nonsus_urls og_tpl og_ua ua_nodoc ua_nozip" ex = "ah_cli ah_gen css_browser dbpath hist ipu js_browser js_other lf_url mime mimes no_forget no_hash no_idx nonsus_urls og_tpl og_ua ua_nodoc ua_nozip"
ka.update(**{k: None for k in ex.split()}) ka.update(**{k: None for k in ex.split()})
ex = "gid uid" ex = "gid uid"
@@ -316,6 +316,7 @@ class VHttpSrv(object):
self.g403 = Garda("") self.g403 = Garda("")
self.gurl = Garda("") self.gurl = Garda("")
self.ico = Ico(args)
self.thumbcli = None self.thumbcli = None
self.u2idx = None self.u2idx = None
@@ -357,7 +358,6 @@ class VHttpConn(object):
Ctor = VHttpSrvUp2k if use_up2k else VHttpSrv Ctor = VHttpSrvUp2k if use_up2k else VHttpSrv
self.hsrv = Ctor(args, asrv, log) self.hsrv = Ctor(args, asrv, log)
self.ico = Ico(args)
self.ipr = None self.ipr = None
self.ipa_nm = None self.ipa_nm = None
self.ipar_nm = None self.ipar_nm = None