From f5e333a17a5221dc8703e6718b0644698075a22b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Pierre?= Date: Sat, 14 Sep 2024 09:56:15 +1200 Subject: [PATCH] [Fix] files: was serving an iterator --- src/py/extra/server.py | 2 ++ src/py/extra/services/files.py | 42 +++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/py/extra/server.py b/src/py/extra/server.py index 7f6d64f..c93d21f 100644 --- a/src/py/extra/server.py +++ b/src/py/extra/server.py @@ -277,6 +277,7 @@ async def SendResponse( await loop.sock_sendall(client, SERVER_ERROR) except Exception as e: exception(e) + return res @classmethod @@ -287,6 +288,7 @@ async def Serve( ) -> None: server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + server.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) server.bind((options.host, options.port)) # The argument is the backlog of connections that will be accepted before # they are refused. diff --git a/src/py/extra/services/files.py b/src/py/extra/services/files.py index e5bb7eb..9141633 100644 --- a/src/py/extra/services/files.py +++ b/src/py/extra/services/files.py @@ -107,27 +107,33 @@ def renderDir( ) breadcrumbs.append("/") return request.respondHTML( - html( - H.html( - H.head( - H.meta(charset="utf-8"), - H.meta( - name="viewport", - content="width=device-width, initial-scale=1.0", - ), - H.title(path), - H.style(FILE_CSS), - H.body( - H.h1( - "Listing for ", - H.a(f"{parent}/", href=f"/{parent}/") if parent else "", - current, + "".join( + html( + H.html( + H.head( + H.meta(charset="utf-8"), + H.meta( + name="viewport", + content="width=device-width, initial-scale=1.0", + ), + H.title(path), + H.style(FILE_CSS), + H.body( + H.h1( + "Listing for ", + ( + H.a(f"{parent}/", href=f"/{parent}/") + if parent + else "" + ), + current, + ), + *nodes, ), - *nodes, ), ), - ), - doctype="html", + doctype="html", + ) ) )