From 727c03205967c104da81f267e7c1bf380d74c370 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 29 May 2020 20:21:08 +0100 Subject: [PATCH] Earlier favicon access --- daemon.py | 72 +++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/daemon.py b/daemon.py index be68e5ce4..282076aa4 100644 --- a/daemon.py +++ b/daemon.py @@ -1105,6 +1105,42 @@ class PubServer(BaseHTTPRequestHandler): self._benchmarkGETtimings(GETstartTime, GETtimings, 4) + # favicon image + if 'favicon.ico' in self.path: + favFilename = 'favicon.ico' + # custom favicon + faviconFilename = \ + self.server.baseDir + '/' + favFilename + if not os.path.isfile(faviconFilename): + # default favicon + faviconFilename = \ + self.server.baseDir + '/img/icons/' + favFilename + if self._etag_exists(faviconFilename): + # The file has not changed + self._304() + return + if self.server.iconsCache.get(favFilename): + favBinary = self.server.iconsCache[favFilename] + self._set_headers_etag(faviconFilename, + 'image/x-icon', + favBinary, cookie, + callingDomain) + self._write(favBinary) + return + else: + if os.path.isfile(faviconFilename): + with open(faviconFilename, 'rb') as favFile: + favBinary = favFile.read() + self._set_headers_etag(faviconFilename, + 'image/x-icon', + favBinary, cookie, + callingDomain) + self._write(favBinary) + self.server.iconsCache[favFilename] = favBinary + return + self._404() + return + # check authorization authorized = self._isAuthorized() if self.server.debug: @@ -1142,42 +1178,6 @@ class PubServer(BaseHTTPRequestHandler): self._400() return - # favicon image - if 'favicon.ico' in self.path: - favFilename = 'favicon.ico' - # custom favicon - faviconFilename = \ - self.server.baseDir + '/' + favFilename - if not os.path.isfile(faviconFilename): - # default favicon - faviconFilename = \ - self.server.baseDir + '/img/icons/' + favFilename - if self._etag_exists(faviconFilename): - # The file has not changed - self._304() - return - if self.server.iconsCache.get(favFilename): - favBinary = self.server.iconsCache[favFilename] - self._set_headers_etag(faviconFilename, - 'image/x-icon', - favBinary, cookie, - callingDomain) - self._write(favBinary) - return - else: - if os.path.isfile(faviconFilename): - with open(faviconFilename, 'rb') as favFile: - favBinary = favFile.read() - self._set_headers_etag(faviconFilename, - 'image/x-icon', - favBinary, cookie, - callingDomain) - self._write(favBinary) - self.server.iconsCache[favFilename] = favBinary - return - self._404() - return - # get fonts if htmlGET and '/fonts/' in self.path: fontStr = self.path.split('/fonts/')[1]