From 73f7249c5f9796a4ee3e0eceddee71c78543bfc5 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 16 Dec 2024 00:53:22 +0100 Subject: [PATCH] decode and log request URLs; closes #125 as processing of a HTTP request begins (GET, HEAD, PUT, POST, ...), the original query line is printed in its encoded form. This makes debugging easier, since there is no ambiguity in how the client phrased its request. however, this results in very opaque logs for non-ascii languages; basically a wall of percent-encoded characters. Avoid this issue by printing an additional log-message if the URL contains `%`, immediately below the original url-encoded entry. also fix tests on macos, and an unrelated bad logmsg in up2k --- copyparty/httpcli.py | 22 +++++++++++++++++++++- copyparty/up2k.py | 2 +- tests/util.py | 8 -------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 9ea4c089..df2ec1bb 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -1118,6 +1118,8 @@ class HttpCli(object): logmsg += " [\033[36m" + rval + "\033[0m]" self.log(logmsg) + if "%" in self.req: + self.log(" `-- %r" % (self.vpath,)) # "embedded" resources if self.vpath.startswith(".cpr"): @@ -1381,6 +1383,8 @@ class HttpCli(object): def handle_propfind(self) -> bool: if self.do_log: self.log("PFIND %s @%s" % (self.req, self.uname)) + if "%" in self.req: + self.log(" `-- %r" % (self.vpath,)) if self.args.no_dav: raise Pebkac(405, "WebDAV is disabled in server config") @@ -1562,6 +1566,8 @@ class HttpCli(object): def handle_proppatch(self) -> bool: if self.do_log: self.log("PPATCH %s @%s" % (self.req, self.uname)) + if "%" in self.req: + self.log(" `-- %r" % (self.vpath,)) if self.args.no_dav: raise Pebkac(405, "WebDAV is disabled in server config") @@ -1617,6 +1623,8 @@ class HttpCli(object): def handle_lock(self) -> bool: if self.do_log: self.log("LOCK %s @%s" % (self.req, self.uname)) + if "%" in self.req: + self.log(" `-- %r" % (self.vpath,)) if self.args.no_dav: raise Pebkac(405, "WebDAV is disabled in server config") @@ -1682,6 +1690,8 @@ class HttpCli(object): def handle_unlock(self) -> bool: if self.do_log: self.log("UNLOCK %s @%s" % (self.req, self.uname)) + if "%" in self.req: + self.log(" `-- %r" % (self.vpath,)) if self.args.no_dav: raise Pebkac(405, "WebDAV is disabled in server config") @@ -1699,6 +1709,8 @@ class HttpCli(object): if self.do_log: self.log("MKCOL %s @%s" % (self.req, self.uname)) + if "%" in self.req: + self.log(" `-- %r" % (self.vpath,)) try: return self._mkdir(self.vpath, True) @@ -1750,6 +1762,8 @@ class HttpCli(object): def handle_options(self) -> bool: if self.do_log: self.log("OPTIONS %s @%s" % (self.req, self.uname)) + if "%" in self.req: + self.log(" `-- %r" % (self.vpath,)) oh = self.out_headers oh["Allow"] = ", ".join(self.conn.hsrv.mallow) @@ -1765,10 +1779,14 @@ class HttpCli(object): def handle_delete(self) -> bool: self.log("DELETE %s @%s" % (self.req, self.uname)) + if "%" in self.req: + self.log(" `-- %r" % (self.vpath,)) return self.handle_rm([]) def handle_put(self) -> bool: - self.log("PUT %s @%s" % (self.req, self.uname)) + self.log("PUT %s @%s" % (self.req, self.uname)) + if "%" in self.req: + self.log(" `-- %r" % (self.vpath,)) if not self.can_write: t = "user %s does not have write-access under /%s" @@ -1787,6 +1805,8 @@ class HttpCli(object): def handle_post(self) -> bool: self.log("POST %s @%s" % (self.req, self.uname)) + if "%" in self.req: + self.log(" `-- %r" % (self.vpath,)) if self.headers.get("expect", "").lower() == "100-continue": try: diff --git a/copyparty/up2k.py b/copyparty/up2k.py index 66a52837..510f3d5c 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -3937,7 +3937,7 @@ class Up2k(object): if jrem == rem: if job["ptop"] != ptop: t = "job.ptop [%s] != vol.ptop [%s] ??" - raise Exception(t % (job["ptop"] != ptop)) + raise Exception(t % (job["ptop"], ptop)) partial = vn.canonical(vjoin(job["prel"], job["tnam"])) break if partial: diff --git a/tests/util.py b/tests/util.py index 2cb19d88..e9369093 100644 --- a/tests/util.py +++ b/tests/util.py @@ -33,14 +33,6 @@ def eprint(*a, **ka): sys.stderr.flush() -if MACOS: - import posixpath - - posixpath.islink = nah - os.path.islink = nah - # 25% faster; until any tests do symlink stuff - - from copyparty.__main__ import init_E from copyparty.broker_thr import BrokerThr from copyparty.ico import Ico