Mercurial > libervia-web
changeset 553:8492c2bb463b
server_side: enable HTTP gzip compression
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 19 Sep 2014 15:39:12 +0200 |
parents | 50ebe9b8129f |
children | 471b6babe960 |
files | src/server/server.py |
diffstat | 1 files changed, 19 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/server/server.py Thu Sep 18 11:47:49 2014 +0200 +++ b/src/server/server.py Fri Sep 19 15:39:12 2014 +0200 @@ -21,7 +21,7 @@ from twisted.internet import reactor, defer from twisted.web import server from twisted.web.static import File -from twisted.web.resource import Resource, NoResource +from twisted.web.resource import Resource, NoResource, EncodingResourceWrapper from twisted.web.util import Redirect, redirectTo from twisted.python.components import registerAdapter from twisted.python.failure import Failure @@ -1056,18 +1056,24 @@ self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name), "plugin") self.media_dir = self.bridge.getConfig('', 'media_dir') self.local_dir = self.bridge.getConfig('', 'local_dir') - root.putChild('', Redirect('libervia.html')) - root.putChild('json_signal_api', self.signal_handler) - root.putChild('json_api', MethodHandler(self)) - root.putChild('register_api', _register) - root.putChild('upload_radiocol', _upload_radiocol) - root.putChild('upload_avatar', _upload_avatar) - root.putChild('blog', MicroBlog(self)) - root.putChild('css', ProtectedFile(self.server_css_dir)) - root.putChild(os.path.dirname(C.MEDIA_DIR), ProtectedFile(self.media_dir)) - root.putChild(os.path.dirname(C.AVATARS_DIR), ProtectedFile(os.path.join(self.local_dir, C.AVATARS_DIR))) - root.putChild('radiocol', ProtectedFile(_upload_radiocol.getTmpDir(), defaultType="audio/ogg")) # We cheat for PoC because we know we are on the same host, so we use directly upload dir - self.site = server.Site(root) + + def putChild(path, resource): + """Add a child to the root resource""" + root.putChild(path, EncodingResourceWrapper(resource, [server.GzipEncoderFactory()])) + + putChild('', Redirect('libervia.html')) + putChild('json_signal_api', self.signal_handler) + putChild('json_api', MethodHandler(self)) + putChild('register_api', _register) + putChild('upload_radiocol', _upload_radiocol) + putChild('upload_avatar', _upload_avatar) + putChild('blog', MicroBlog(self)) + putChild('css', ProtectedFile(self.server_css_dir)) + putChild(os.path.dirname(C.MEDIA_DIR), ProtectedFile(self.media_dir)) + putChild(os.path.dirname(C.AVATARS_DIR), ProtectedFile(os.path.join(self.local_dir, C.AVATARS_DIR))) + putChild('radiocol', ProtectedFile(_upload_radiocol.getTmpDir(), defaultType="audio/ogg")) # We cheat for PoC because we know we are on the same host, so we use directly upload dir + wrapped = EncodingResourceWrapper(root, [server.GzipEncoderFactory()]) + self.site = server.Site(wrapped) self.site.sessionFactory = LiberviaSession self.bridge.getReady(lambda: self.initialised.callback(None),