From 7678a91b0ebeb12df19d2be8c187fd423f69e83c Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 25 Oct 2024 20:00:19 +0000 Subject: [PATCH] debug: `--ohead` (log response headers) --- copyparty/__main__.py | 4 ++++ copyparty/authsrv.py | 2 +- copyparty/httpcli.py | 13 +++++++++++++ tests/util.py | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 2e4365f0..fb1de83c 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1307,6 +1307,7 @@ def add_logging(ap): ap2.add_argument("--log-conn", action="store_true", help="debug: print tcp-server msgs") ap2.add_argument("--log-htp", action="store_true", help="debug: print http-server threadpool scaling") ap2.add_argument("--ihead", metavar="HEADER", type=u, action='append', help="print request \033[33mHEADER\033[0m; [\033[32m*\033[0m]=all") + ap2.add_argument("--ohead", metavar="HEADER", type=u, action='append', help="print response \033[33mHEADER\033[0m; [\033[32m*\033[0m]=all") ap2.add_argument("--lf-url", metavar="RE", type=u, default=r"^/\.cpr/|\?th=[wj]$|/\.(_|ql_|DS_Store$|localized$)", help="dont log URLs matching regex \033[33mRE\033[0m") @@ -1757,6 +1758,9 @@ def main(argv: Optional[list[str]] = None) -> None: if al.ihead: al.ihead = [x.lower() for x in al.ihead] + if al.ohead: + al.ohead = [x.lower() for x in al.ohead] + if HAVE_SSL: if al.ssl_ver: configure_ssl_ver(al) diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index f67b6870..ddf57c71 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -2640,7 +2640,7 @@ class AuthSrv(object): ] csv = set("i p th_covers zm_on zm_off zs_on zs_off".split()) - zs = "c ihead mtm mtp on403 on404 xad xar xau xiu xban xbd xbr xbu xm" + zs = "c ihead ohead mtm mtp on403 on404 xad xar xau xiu xban xbd xbr xbu xm" lst = set(zs.split()) askip = set("a v c vc cgen exp_lg exp_md theme".split()) fskip = set("exp_lg exp_md mv_re_r mv_re_t rm_re_r rm_re_t".split()) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 1bef4dd2..4a8b97d3 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -863,6 +863,19 @@ class HttpCli(object): self.cbonk(self.conn.hsrv.gmal, zs, "cc_hdr", "Cc in out-hdr") raise Pebkac(999) + if self.args.ohead and self.do_log: + keys = self.args.ohead + if "*" in keys: + lines = response[1:] + else: + lines = [] + for zs in response[1:]: + if zs.split(":")[0].lower() in keys: + lines.append(zs) + for zs in lines: + hk, hv = zs.split(": ") + self.log("[O] {}: \033[33m[{}]".format(hk, hv), 5) + response.append("\r\n") try: self.s.sendall("\r\n".join(response).encode("utf-8")) diff --git a/tests/util.py b/tests/util.py index 01f4e480..e0421462 100644 --- a/tests/util.py +++ b/tests/util.py @@ -122,7 +122,7 @@ class Cfg(Namespace): def __init__(self, a=None, v=None, c=None, **ka0): ka = {} - ex = "chpw daw dav_auth dav_inf dav_mac dav_rt e2d e2ds e2dsa e2t e2ts e2tsr e2v e2vu e2vp early_ban ed emp exp force_js getmod grid gsel hardlink ih ihead magic hardlink_only nid nih no_acode no_athumb no_clone no_dav no_db_ip no_del no_dirsz no_dupe no_lifetime no_logues no_mv no_pipe no_poll no_readme no_robots no_sb_md no_sb_lg no_scandir no_tarcmp no_thumb no_vthumb no_zip nrand nw og og_no_head og_s_title q rand re_dirsz rss smb srch_dbg stats uqe vague_403 vc ver write_uplog xdev xlink xvol zs" + ex = "chpw daw dav_auth dav_inf dav_mac dav_rt e2d e2ds e2dsa e2t e2ts e2tsr e2v e2vu e2vp early_ban ed emp exp force_js getmod grid gsel hardlink ih ihead magic hardlink_only nid nih no_acode no_athumb no_clone no_dav no_db_ip no_del no_dirsz no_dupe no_lifetime no_logues no_mv no_pipe no_poll no_readme no_robots no_sb_md no_sb_lg no_scandir no_tarcmp no_thumb no_vthumb no_zip nrand nw og og_no_head og_s_title ohead q rand re_dirsz rss smb srch_dbg stats uqe vague_403 vc ver write_uplog xdev xlink xvol zs" ka.update(**{k: False for k in ex.split()}) ex = "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 re_dhash plain_ip"