From 8689900a386fb1c767350e70dc02774fc9cc39c5 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 17 Aug 2009 20:08:20 +0200 Subject: webinterface cache control, curl fix --- module/web/WebServer.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'module/web/WebServer.py') diff --git a/module/web/WebServer.py b/module/web/WebServer.py index ad0d03512..cd5c57a70 100644 --- a/module/web/WebServer.py +++ b/module/web/WebServer.py @@ -21,6 +21,7 @@ import threading import bottle +import time from bottle import abort from bottle import db from bottle import debug @@ -34,10 +35,10 @@ from bottle import template from bottle import validate -debug(True) core = None PATH = "./module/web/" +TIME = time.strftime("%a, %d %b %Y 00:00:00 +0000", time.localtime()) #set time to current day @route('/', method= 'POST') def home(): @@ -52,26 +53,41 @@ def login(): @route('/favicon.ico') def favicon(): - send_file('pyload.ico', PATH + 'static/') + redirect('/static/favicon.ico') @route('static/:section/:filename') def static_folder(section, filename): + + if request.HEADER("HTTP_IF_MODIFIED_SINCE") == TIME: abort(304, "Not Modified") + + response.header['Last-Modified'] = TIME send_file(filename, root=(PATH + 'static/' + section)) @route('/static/:filename') def static_file(filename): + + if request.HEADER("HTTP_IF_MODIFIED_SINCE") == TIME: abort(304, "Not Modified") + + response.header['Last-Modified'] = TIME send_file(filename, root=(PATH + 'static/')) class WebServer(threading.Thread): def __init__(self, pycore): threading.Thread.__init__(self) - global core + global core, TIME core = pycore self.core = pycore self.setDaemon(True) + if pycore.config['general']['debug_mode']: + bottle.debug(True) + TIME = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime()) + else: + bottle.debug(False) + bottle.TEMPLATE_PATH.append('./module/web/templates/%s.tpl') def run(self): - run(host='localhost', port=int(self.core.config['webinterface']['port'])) \ No newline at end of file + self.core.logger.info("Starting Webinterface on port %s" % self.core.config['webinterface']['port']) + run(host='localhost', port=int(self.core.config['webinterface']['port']), quiet=True) -- cgit v1.2.3