From 3c42d5d76da5eda2ce6bedd954269161259b2289 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 30 Aug 2013 22:48:46 +0200 Subject: Properly return favicon.ico if it exists. --- fbin.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fbin.py b/fbin.py index f9ca772..51d3203 100755 --- a/fbin.py +++ b/fbin.py @@ -443,13 +443,17 @@ class Application(object): def static(self, environ, start_response, path): filename = path[1] - if not filename in ('style.css', 'no-thumbnail.png'): + if not filename in ('style.css', 'no-thumbnail.png', 'favicon.ico'): start_response('404 Not Found', []) return [] + filepath = os.path.join(settings.static_root, filename) + if not os.path.exists(filepath): + start_response('404 Not Found', []) + return [] mime = mimetypes.guess_type(filename, strict = False)[0] or 'application/octet-stream' start_response('200 OK', [('Content-Type', mime)]) - return open(os.path.join(settings.static_root, filename), 'rb') + return open(filepath, 'rb') def help(self, environ, start_response, path): c = Cookie.SimpleCookie(environ['HTTP_COOKIE'] if 'HTTP_COOKIE' in environ else None) @@ -586,6 +590,8 @@ class Application(object): module = path[0] if len(path) else '' if len(module) and module in 'fulshmitorcda': return getattr(self, module)(environ, start_response, path) + elif path == ['favicon.ico']: + return self.static(environ, start_response, ['s'] + path) else: start_response('302 Found', [('Location', settings.virtual_root + 'u')]) return [] -- cgit v1.2.3