Skip to content

Commit

Permalink
✨ Favicon
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelWaldvogel committed Nov 11, 2021
1 parent dcff4aa commit e775337
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/) and this

## Added

- Support for `favicon.ico` (served as `image/png`, as that is the most common type today)

## Fixed

- The fix for malformed request made things work. Better fix.
Expand Down
44 changes: 22 additions & 22 deletions zeitgitter/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,29 +115,29 @@ def do_GET(self):
b'ZEITGITTER_COUNTRY': bytes(zeitgitter.config.arg.country, 'UTF-8')}

if self.path == '/':
self.send_file('text/html', 'index.html', replace=subst)
else:
match = re.match(r'^/([a-z0-9][-_.a-z0-9]*)\.([a-z]*)$',
self.path, re.IGNORECASE)
mimemap = {
'html': 'text/html',
'txt': 'text/plain',
'xml': 'text/xml',
'css': 'text/css',
'js': 'text/javascript',
'png': 'image/png',
'svg': 'image/svg+xml',
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg'}
if match and match.group(2) in mimemap:
mime = mimemap[match.group(2)]
if mime.startswith('text/'):
self.send_file(mime, self.path[1:], replace=subst)
else:
self.send_file(mimemap[match.group(2)], self.path[1:])
self.path = '/index.html'
match = re.match(r'^/([a-z0-9][-_.a-z0-9]*)\.([a-z]*)$',
self.path, re.IGNORECASE)
mimemap = {
'html': 'text/html',
'txt': 'text/plain',
'xml': 'text/xml',
'css': 'text/css',
'js': 'text/javascript',
'png': 'image/png',
'ico': 'image/png',
'svg': 'image/svg+xml',
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg'}
if match and match.group(2) in mimemap:
mime = mimemap[match.group(2)]
if mime.startswith('text/'):
self.send_file(mime, self.path[1:], replace=subst)
else:
self.send_bodyerr(406, "Illegal file name",
"<p>This type of file/path is not served here.</p>")
self.send_file(mime, self.path[1:])
else:
self.send_bodyerr(406, "Illegal file name",
"<p>This type of file/path is not served here.</p>")


stamper = None
Expand Down
Binary file added zeitgitter/web/favicon.ico
Binary file not shown.

0 comments on commit e775337

Please sign in to comment.