summaryrefslogtreecommitdiffstats
path: root/pyload/web/pyload_app.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-09-11 13:07:18 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-09-11 13:07:18 +0200
commit6104151b9f5e682ba1f3c2e09c28604066b30fdf (patch)
treeb9a1d6d6e84fdcd58ed3b7130a72439b7c37c8f0 /pyload/web/pyload_app.py
parentcontainer upload and url parser for linkgrabber (diff)
downloadpyload-6104151b9f5e682ba1f3c2e09c28604066b30fdf.tar.xz
gzip files on build, disabled gzip middleware
Diffstat (limited to 'pyload/web/pyload_app.py')
-rw-r--r--pyload/web/pyload_app.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/pyload/web/pyload_app.py b/pyload/web/pyload_app.py
index 7202c319b..b182816c2 100644
--- a/pyload/web/pyload_app.py
+++ b/pyload/web/pyload_app.py
@@ -17,14 +17,19 @@
@author: RaNaN
"""
import time
-from os.path import join
+from os.path import join, exists
-from bottle import route, static_file, response, redirect, template
+from bottle import route, static_file, response, request, redirect, template
from webinterface import PYLOAD, PROJECT_DIR, SETUP, APP_PATH, UNAVAILALBE
from utils import login_required
+APP_ROOT = join(PROJECT_DIR, APP_PATH)
+
+# Cache file names that are available gzipped
+GZIPPED = {}
+
@route('/icons/<path:path>')
def serve_icon(path):
@@ -64,7 +69,19 @@ def server_static(path):
response.headers['Expires'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT",
time.gmtime(time.time() + 60 * 60 * 24 * 7))
response.headers['Cache-control'] = "public"
- resp = static_file(path, root=join(PROJECT_DIR, APP_PATH))
+
+ # save if this resource is available as gz
+ if path not in GZIPPED:
+ GZIPPED[path] = exists(join(APP_ROOT, path + ".gz"))
+
+ # gzipped and clients accepts it
+ # TODO: index.html is not gzipped, because of template processing
+ 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'
+ 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":
return static_file(path, root=join(PROJECT_DIR, '.tmp'))