diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-09-11 13:07:18 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-09-11 13:07:18 +0200 |
commit | 6104151b9f5e682ba1f3c2e09c28604066b30fdf (patch) | |
tree | b9a1d6d6e84fdcd58ed3b7130a72439b7c37c8f0 | |
parent | container upload and url parser for linkgrabber (diff) | |
download | pyload-6104151b9f5e682ba1f3c2e09c28604066b30fdf.tar.xz |
gzip files on build, disabled gzip middleware
-rw-r--r-- | pyload/config/default.py | 2 | ||||
-rw-r--r-- | pyload/web/Gruntfile.js | 15 | ||||
-rw-r--r-- | pyload/web/middlewares.py | 4 | ||||
-rw-r--r-- | pyload/web/package.json | 1 | ||||
-rw-r--r-- | pyload/web/pyload_app.py | 23 | ||||
-rw-r--r-- | pyload/web/webinterface.py | 3 |
6 files changed, 38 insertions, 10 deletions
diff --git a/pyload/config/default.py b/pyload/config/default.py index 103dcdebb..0ae1a2649 100644 --- a/pyload/config/default.py +++ b/pyload/config/default.py @@ -67,7 +67,7 @@ def make_config(config): ("host", "ip", _("IP"), "0.0.0.0"), ("https", "bool", _("Use HTTPS"), False), ("port", "int", _("Port"), 8001), - ("develop", "str", _("Development mode"), False), + ("develop", "bool", _("Development mode"), False), ]) config.addConfigSection("proxy", _("Proxy"), _("Description"), _("Long description"), diff --git a/pyload/web/Gruntfile.js b/pyload/web/Gruntfile.js index 92bb33da9..0a97e7360 100644 --- a/pyload/web/Gruntfile.js +++ b/pyload/web/Gruntfile.js @@ -295,6 +295,18 @@ module.exports = function(grunt) { src: ['**/*.js', '!*.min.js'] } }, + compress: { + main: { + options: { + mode: 'gzip' + }, + expand: true, + cwd: '<%= yeoman.dist %>', + dest: '<%= yeoman.dist %>', + src: ['**/*.{js,css,html}'] + } + }, + // Put files not handled in other tasks here copy: { // Copy files from third party libraries @@ -414,7 +426,8 @@ module.exports = function(grunt) { 'concurrent:dist', // Run minimisation 'uglify', // minify js 'rev', - 'usemin' + 'usemin', + 'compress' ]); grunt.registerTask('default', [ diff --git a/pyload/web/middlewares.py b/pyload/web/middlewares.py index aeb65fde5..074681b8f 100644 --- a/pyload/web/middlewares.py +++ b/pyload/web/middlewares.py @@ -38,6 +38,7 @@ class PrefixMiddleware(object): # WSGI middleware # Gzip-encodes the response. +# TODO: not in use anymore, because of pre-gzipped resources class GZipMiddleWare(object): def __init__(self, application, compress_level=6): @@ -111,9 +112,6 @@ class GzipResponse(object): out.close() return [s] - # TODO: also writes large files to stringbuffer - # avoids optimized send_file and causes memory shortage - # pre-gzipped resources would make this obsolete def finish_response(self, app_iter): if self.compressible: output = gzip.GzipFile(mode='wb', compresslevel=self.compress_level, diff --git a/pyload/web/package.json b/pyload/web/package.json index fdd7b62c4..e1a2defb7 100644 --- a/pyload/web/package.json +++ b/pyload/web/package.json @@ -20,6 +20,7 @@ "grunt-contrib-requirejs": "~0.4.0", "grunt-contrib-imagemin": "~0.1.3", "grunt-contrib-watch": "~0.4.0", + "grunt-contrib-compress": "~0.5.0", "grunt-rev": "~0.1.0", "grunt-usemin": "~0.1.10", "grunt-mocha": "~0.3.0", 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')) diff --git a/pyload/web/webinterface.py b/pyload/web/webinterface.py index 206603f27..b0faf94a9 100644 --- a/pyload/web/webinterface.py +++ b/pyload/web/webinterface.py @@ -26,7 +26,7 @@ PYLOAD_DIR = abspath(join(PROJECT_DIR, "..", "..")) import bottle from bottle import run, app -from middlewares import StripPathMiddleware, GZipMiddleWare, PrefixMiddleware +from middlewares import StripPathMiddleware, PrefixMiddleware SETUP = None PYLOAD = None @@ -80,7 +80,6 @@ session_opts = { session = SessionMiddleware(app(), session_opts) web = StripPathMiddleware(session) -web = GZipMiddleWare(web) if PREFIX: web = PrefixMiddleware(web, prefix=PREFIX) |