main
Bob Mottram 2020-05-29 20:37:33 +01:00
parent de9972153a
commit 56a223f863
1 changed files with 10 additions and 2 deletions

View File

@ -1107,10 +1107,13 @@ class PubServer(BaseHTTPRequestHandler):
# favicon image # favicon image
if 'favicon.ico' in self.path: if 'favicon.ico' in self.path:
favType = 'image/x-icon'
favFilename = 'favicon.ico' favFilename = 'favicon.ico'
if self.headers.get('Accept'): if self.headers.get('Accept'):
if 'image/webp' in self.headers['Accept']: if 'image/webp' in self.headers['Accept']:
favType = 'image/webp'
favFilename = 'favicon.webp' favFilename = 'favicon.webp'
print('Sending webp favicon')
# custom favicon # custom favicon
faviconFilename = \ faviconFilename = \
self.server.baseDir + '/' + favFilename self.server.baseDir + '/' + favFilename
@ -1118,28 +1121,33 @@ class PubServer(BaseHTTPRequestHandler):
# default favicon # default favicon
faviconFilename = \ faviconFilename = \
self.server.baseDir + '/img/icons/' + favFilename self.server.baseDir + '/img/icons/' + favFilename
print('faviconFilename: ' + faviconFilename)
if self._etag_exists(faviconFilename): if self._etag_exists(faviconFilename):
# The file has not changed # The file has not changed
self._304() self._304()
return return
if self.server.iconsCache.get(favFilename): if self.server.iconsCache.get(favFilename):
print('Get favicon from cache')
favBinary = self.server.iconsCache[favFilename] favBinary = self.server.iconsCache[favFilename]
self._set_headers_etag(faviconFilename, self._set_headers_etag(faviconFilename,
'image/x-icon', favType,
favBinary, cookie, favBinary, cookie,
callingDomain) callingDomain)
self._write(favBinary) self._write(favBinary)
return return
else: else:
print('Get favicon from file')
if os.path.isfile(faviconFilename): if os.path.isfile(faviconFilename):
print('favicon file found')
with open(faviconFilename, 'rb') as favFile: with open(faviconFilename, 'rb') as favFile:
favBinary = favFile.read() favBinary = favFile.read()
self._set_headers_etag(faviconFilename, self._set_headers_etag(faviconFilename,
'image/x-icon', favType,
favBinary, cookie, favBinary, cookie,
callingDomain) callingDomain)
self._write(favBinary) self._write(favBinary)
self.server.iconsCache[favFilename] = favBinary self.server.iconsCache[favFilename] = favBinary
print('favicon file send')
return return
self._404() self._404()
return return