From 80d5aad05d7377ce63f036876f66de0262f7c7da Mon Sep 17 00:00:00 2001 From: Kumi Date: Mon, 22 Jan 2024 08:39:37 +0100 Subject: [PATCH] Add index page for PyFiche Lines server Implemented a welcoming index page for the PyFiche Lines HTTP server. Now, when users access the root URL, they are greeted with an informative page that includes a brief introduction to the service, its purpose, and a link to the project's repository for additional information. This enhancement improves user experience by providing context and guidance for new visitors to the server. --- src/pyfiche/classes/lines.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/pyfiche/classes/lines.py b/src/pyfiche/classes/lines.py index 59cf4d1..4fa8149 100644 --- a/src/pyfiche/classes/lines.py +++ b/src/pyfiche/classes/lines.py @@ -46,6 +46,13 @@ body {{ """ + INDEX_CONTENT = BASE_HTML.format( + content="""

PyFiche Lines

+

Welcome to PyFiche Lines, a HTTP server for PyFiche.

+

PyFiche Lines is a HTTP server for PyFiche. It allows you to view files uploaded through PyFiche in your browser.

+

For more information, see the PyFiche Git repo.

""" + ) + server_version = "PyFiche Lines/dev" def do_POST(self): @@ -162,6 +169,16 @@ body {{ url = urlparse(self.path.rstrip("/")) + # If the URL is /, display the index page + if url.path == "/": + self.send_response(200) + self.send_header("Content-Type", "text/html") + self.send_header("Content-Length", len(self.INDEX_CONTENT)) + self.end_headers() + + self.wfile.write(self.INDEX_CONTENT.encode("utf-8")) + return + # Discard any URLs that aren't of the form / or //raw if not len(url.path.split("/")) in [2, 3]: return self.not_found()