summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyload/Core.py18
-rw-r--r--pyload/web/pyload_app.py28
2 files changed, 24 insertions, 22 deletions
diff --git a/pyload/Core.py b/pyload/Core.py
index a13346567..74739f800 100644
--- a/pyload/Core.py
+++ b/pyload/Core.py
@@ -35,7 +35,6 @@ from time import time, sleep
from traceback import print_exc
import locale
-
locale.locale_alias = locale.windows_locale = {} #save ~100kb ram, no known sideeffects for now
import subprocess
@@ -503,22 +502,7 @@ class Core(object):
def init_logger(self, level):
console = logging.StreamHandler(sys.stdout)
- # try to get a time formatting depending on system locale
- datefmt = None
- try: # change current locale to default if it is not set
- current_locale = locale.getlocale()
- if current_locale == (None, None):
- current_locale = locale.setlocale(locale.LC_ALL, '')
-
- # We use timeformat provided by locale when available
- if current_locale != (None, None):
- datefmt = locale.nl_langinfo(locale.D_FMT) + " " + locale.nl_langinfo(locale.T_FMT)
- except: # something did go wrong, locale is heavily platform dependant
- pass
-
- # default formatting when no one was obtained (ex.: 2013-10-22 18:27:46)
- if not datefmt:
- datefmt = "%Y-%m-%d %H:%M:%S"
+ datefmt = "%Y-%m-%d %H:%M:%S"
# file handler formatter
fhfmt = "%(asctime)s %(levelname)-8s %(message)s"
diff --git a/pyload/web/pyload_app.py b/pyload/web/pyload_app.py
index 597f1525b..70ada0b53 100644
--- a/pyload/web/pyload_app.py
+++ b/pyload/web/pyload_app.py
@@ -65,6 +65,10 @@ def i18n(lang=None):
@route('/')
def index():
+ # the browser should not set this, but remove in case to to avoid cached requests
+ if 'HTTP_IF_MODIFIED_SINCE' in request.environ:
+ del request.environ['HTTP_IF_MODIFIED_SINCE']
+
if UNAVAILALBE:
return serve_static("unavailable.html")
@@ -85,8 +89,11 @@ def index():
resp.body = template(content, ws=ws, web=web, setup=setup, external=external, prefix=PREFIX)
resp.content_length = len(resp.body)
- # tell the browser to don't cache it
- resp.headers["Cache-Control"] = "no-cache, must-revalidate"
+ # these page should not be cached at all
+ resp.headers.append("Cache-Control", "no-cache")
+ # they are rendered and last modified would be wrong
+ if "Last-Modified" in resp.headers:
+ del resp.headers["Last-Modified"]
return resp
@@ -99,17 +106,28 @@ def serve_static(path):
# gzipped and clients accepts it
# TODO: index.html is not gzipped, because of template processing
+ gzipped = False
if GZIPPED[path] and "gzip" in request.get_header("Accept-Encoding", "") and path != "index.html":
- response.headers['Vary'] = 'Accept-Encoding'
- response.headers['Content-Encoding'] = 'gzip'
+ gzipped = True
path += ".gz"
resp = static_file(path, root=APP_ROOT)
+
# Also serve from .tmp folder in dev mode
if resp.status_code == 404 and APP_PATH == "app":
resp = static_file(path, root=join(PROJECT_DIR, '.tmp'))
- if resp.status_code == 200:
+ if path.endswith(".html") or path.endswith(".html.gz"):
+ # tell the browser all html files must be revalidated
+ resp.headers["Cache-Control"] = "must-revalidate"
+ elif resp.status_code == 200:
+ # expires after 7 days
+ resp.headers['Expires'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT",
+ time.gmtime(time.time() + 60 * 60 * 24 * 7))
resp.headers['Cache-control'] = "public"
+ if gzipped:
+ resp.headers['Vary'] = 'Accept-Encoding'
+ resp.headers['Content-Encoding'] = 'gzip'
+
return resp \ No newline at end of file