From 4587ce677125f52079cba15737c804357801c79a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 22 Jun 2020 13:05:58 +0100 Subject: [PATCH] http return codes --- daemon.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/daemon.py b/daemon.py index 4078d4ee8..1b7e53b96 100644 --- a/daemon.py +++ b/daemon.py @@ -586,9 +586,18 @@ class PubServer(BaseHTTPRequestHandler): self.send_header('X-Robots-Tag', 'noindex') self.end_headers() - def _httpReturnCode(self, httpCode: int, httpDescription: str) -> None: - msg = "

" + str(httpCode) + " " + \ - httpDescription + "

" + def _httpReturnCode(self, httpCode: int, httpDescription: str, + longDescription: str) -> None: + msg = \ + '' + str(httpCode) + '' \ + '' \ + '
' + str(httpCode) + '
' \ + '
' + httpDescription + '
' \ + '
' + longDescription + '
' \ + '' msg = msg.encode('utf-8') self.send_response(httpCode) self.send_header('Content-Type', 'text/html; charset=utf-8') @@ -602,19 +611,25 @@ class PubServer(BaseHTTPRequestHandler): print(e) def _200(self) -> None: - self._httpReturnCode(200, 'Ok') + self._httpReturnCode(200, 'Ok', + 'This is nothing less than an utter triumph.') def _404(self) -> None: - self._httpReturnCode(404, 'Not Found') + self._httpReturnCode(404, 'Not Found', + 'These are not the droids you are looking for.') def _304(self) -> None: - self._httpReturnCode(304, 'Resource has not changed') + self._httpReturnCode(304, 'Not changed', + 'The contents of your local cache are ' + + 'up to date.') def _400(self) -> None: - self._httpReturnCode(400, 'Bad Request') + self._httpReturnCode(400, 'Bad Request', + 'Better luck next time.') def _503(self) -> None: - self._httpReturnCode(503, 'Service Unavailable') + self._httpReturnCode(503, 'Unavailable', + 'The server is busy. Please try again later.') def _write(self, msg) -> None: tries = 0