From 5d107acf09b9eefba76d6579a1f31dd481a7700e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 15 Nov 2019 14:03:43 +0000 Subject: [PATCH] Returning http codes --- daemon.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/daemon.py b/daemon.py index a3383d12..db5c2838 100644 --- a/daemon.py +++ b/daemon.py @@ -295,9 +295,10 @@ class PubServer(BaseHTTPRequestHandler): self.send_header('X-Robots-Tag','noindex') self.end_headers() - def _404(self) -> None: - msg="

404 Not Found

".encode('utf-8') - self.send_response(404) + def _httpReturnCode(self,httpCode: int,httpDescription: str) -> None + msg="

"+str(httpCode)+" "+httpDescription+"

" + msg=msg.encode('utf-8') + self.send_response(httpCode) self.send_header('Content-Type', 'text/html; charset=utf-8') self.send_header('Content-Length', str(len(msg))) self.send_header('X-Robots-Tag','noindex') @@ -305,9 +306,15 @@ class PubServer(BaseHTTPRequestHandler): try: self.wfile.write(msg) except Exception as e: - print('Error when showing 404') + print('Error when showing '+str(httpCode)) print(e) + def _404(self) -> None: + self._httpReturnCode(404,'Not Found') + + def _400(self) -> None: + self._httpReturnCode(400,'Bad Request') + def _write(self,msg) -> None: tries=0 while tries<5: @@ -879,6 +886,7 @@ class PubServer(BaseHTTPRequestHandler): if self._requestHTTP(): htmlGET=True else: + self._400() return # treat shared inbox paths consistently @@ -1010,6 +1018,7 @@ class PubServer(BaseHTTPRequestHandler): self._set_headers('text/css',len(msg),cookie) self._write(msg) return + self._404() # image on login screen if self.path=='/login.png' or \