From 3aa22cfa636f21ba079e352b81448d675174d59a Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Wed, 3 Jul 2024 09:33:30 +0700 Subject: [PATCH] fix http directory listing --- xpra/net/http/directory_listing.py | 11 ++++++----- xpra/net/http/http_handler.py | 7 +++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/xpra/net/http/directory_listing.py b/xpra/net/http/directory_listing.py index 85a7891ad8..776ad789c9 100644 --- a/xpra/net/http/directory_listing.py +++ b/xpra/net/http/directory_listing.py @@ -3,7 +3,7 @@ # Xpra is released under the terms of the GNU GPL v2, or, at your option, any # later version. See the file COPYING for details. -# duplicated form SimpleHTTPRequestHandler +# duplicated from SimpleHTTPRequestHandler # so that we can re-use it from the quic handler # and also so that we can customize it more easily @@ -52,8 +52,9 @@ def list_directory(path:str): encoded = '\n'.join(r).encode(enc, 'surrogateescape') f = BytesIO() f.write(encoded) - f.seek(0) + contents = f.getvalue() + f.close() return 200, { - "Content-type", f"text/html; charset={enc}", - "Content-Length", str(len(encoded)), - }, f + "Content-type": f"text/html; charset={enc}", + "Content-Length": str(len(encoded)), + }, contents diff --git a/xpra/net/http/http_handler.py b/xpra/net/http/http_handler.py index c68140c71a..4fdf39b452 100644 --- a/xpra/net/http/http_handler.py +++ b/xpra/net/http/http_handler.py @@ -402,8 +402,11 @@ def send_head(self): if not self.directory_listing: self.send_error(403, "Directory listing forbidden") return None - return list_directory(path).read() - + code, headers, body = list_directory(path) + self.send_response(code) + self.extra_headers.update(headers) + self.end_headers() + return body try: code, extra_headers, content = load_path(self.headers, path) lm = extra_headers.get("Last-Modified")