From aae0d3c6a9364ec733f0bc2bb88a80625fcb9f48 Mon Sep 17 00:00:00 2001 From: gpkvt Date: Thu, 11 Aug 2022 10:42:56 +0200 Subject: [PATCH] Add 404 handling --- tts.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tts.py b/tts.py index c3fb01a..f8aba92 100644 --- a/tts.py +++ b/tts.py @@ -225,7 +225,7 @@ class HTTPserv(BaseHTTPRequestHandler): html = fh.read() self.wfile.write(html) - if self.path == '/tts.js': + elif self.path == '/tts.js': self.send_response(200) self.send_header('Content-type', 'text/javascript') self.end_headers() @@ -233,7 +233,7 @@ class HTTPserv(BaseHTTPRequestHandler): html = fh.read() self.wfile.write(html) - if self.path == '/jquery.js': + elif self.path == '/jquery.js': self.send_response(200) self.send_header('Content-type', 'text/javascript') self.end_headers() @@ -241,7 +241,7 @@ class HTTPserv(BaseHTTPRequestHandler): html = fh.read() self.wfile.write(html) - if self.path == '/bootstrap.min.css': + elif self.path == '/bootstrap.min.css': self.send_response(200) self.send_header('Content-type', 'text/css') self.end_headers() @@ -249,7 +249,7 @@ class HTTPserv(BaseHTTPRequestHandler): html = fh.read() self.wfile.write(html) - if self.path.startswith('/tts_queue'): + elif self.path.startswith('/tts_queue'): tts_json = "" tts = {} self.send_response(200) @@ -269,7 +269,7 @@ class HTTPserv(BaseHTTPRequestHandler): tts_json = json.dumps(tts) self.wfile.write(bytes(str(tts_json)+"\n", "utf-8")) - if self.path.startswith('/tts_done'): + elif self.path.startswith('/tts_done'): get_params = parse_qs(self.path) if '/tts_done?id' in get_params: logging.info("Removing message from queue") @@ -284,6 +284,13 @@ class HTTPserv(BaseHTTPRequestHandler): self.end_headers() self.wfile.write(bytes("Internal Server error\n", "utf-8")) + else: + self.send_response(404) + self.send_header('Server', 'TTS') + self.send_header('Content-type', 'text/plain') + self.end_headers() + self.wfile.write(bytes("File not found.\n", "utf-8")) + return def http_serve_forever(httpd):