comparison src/server/server.py @ 553:8492c2bb463b

server_side: enable HTTP gzip compression
author souliane <souliane@mailoo.org>
date Fri, 19 Sep 2014 15:39:12 +0200
parents 0de69fec24e9
children 471b6babe960
comparison
equal deleted inserted replaced
552:50ebe9b8129f 553:8492c2bb463b
19 19
20 from twisted.application import service 20 from twisted.application import service
21 from twisted.internet import reactor, defer 21 from twisted.internet import reactor, defer
22 from twisted.web import server 22 from twisted.web import server
23 from twisted.web.static import File 23 from twisted.web.static import File
24 from twisted.web.resource import Resource, NoResource 24 from twisted.web.resource import Resource, NoResource, EncodingResourceWrapper
25 from twisted.web.util import Redirect, redirectTo 25 from twisted.web.util import Redirect, redirectTo
26 from twisted.python.components import registerAdapter 26 from twisted.python.components import registerAdapter
27 from twisted.python.failure import Failure 27 from twisted.python.failure import Failure
28 from twisted.words.protocols.jabber.jid import JID 28 from twisted.words.protocols.jabber.jid import JID
29 29
1054 'radiocolStarted', 'radiocolPreload', 'radiocolPlay', 'radiocolNoUpload', 'radiocolUploadOk', 'radiocolSongRejected', 'radiocolPlayers', 1054 'radiocolStarted', 'radiocolPreload', 'radiocolPlay', 'radiocolNoUpload', 'radiocolUploadOk', 'radiocolSongRejected', 'radiocolPlayers',
1055 'roomLeft', 'roomUserChangedNick', 'chatStateReceived']: 1055 'roomLeft', 'roomUserChangedNick', 'chatStateReceived']:
1056 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name), "plugin") 1056 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name), "plugin")
1057 self.media_dir = self.bridge.getConfig('', 'media_dir') 1057 self.media_dir = self.bridge.getConfig('', 'media_dir')
1058 self.local_dir = self.bridge.getConfig('', 'local_dir') 1058 self.local_dir = self.bridge.getConfig('', 'local_dir')
1059 root.putChild('', Redirect('libervia.html')) 1059
1060 root.putChild('json_signal_api', self.signal_handler) 1060 def putChild(path, resource):
1061 root.putChild('json_api', MethodHandler(self)) 1061 """Add a child to the root resource"""
1062 root.putChild('register_api', _register) 1062 root.putChild(path, EncodingResourceWrapper(resource, [server.GzipEncoderFactory()]))
1063 root.putChild('upload_radiocol', _upload_radiocol) 1063
1064 root.putChild('upload_avatar', _upload_avatar) 1064 putChild('', Redirect('libervia.html'))
1065 root.putChild('blog', MicroBlog(self)) 1065 putChild('json_signal_api', self.signal_handler)
1066 root.putChild('css', ProtectedFile(self.server_css_dir)) 1066 putChild('json_api', MethodHandler(self))
1067 root.putChild(os.path.dirname(C.MEDIA_DIR), ProtectedFile(self.media_dir)) 1067 putChild('register_api', _register)
1068 root.putChild(os.path.dirname(C.AVATARS_DIR), ProtectedFile(os.path.join(self.local_dir, C.AVATARS_DIR))) 1068 putChild('upload_radiocol', _upload_radiocol)
1069 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 1069 putChild('upload_avatar', _upload_avatar)
1070 self.site = server.Site(root) 1070 putChild('blog', MicroBlog(self))
1071 putChild('css', ProtectedFile(self.server_css_dir))
1072 putChild(os.path.dirname(C.MEDIA_DIR), ProtectedFile(self.media_dir))
1073 putChild(os.path.dirname(C.AVATARS_DIR), ProtectedFile(os.path.join(self.local_dir, C.AVATARS_DIR)))
1074 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
1075 wrapped = EncodingResourceWrapper(root, [server.GzipEncoderFactory()])
1076 self.site = server.Site(wrapped)
1071 self.site.sessionFactory = LiberviaSession 1077 self.site.sessionFactory = LiberviaSession
1072 1078
1073 self.bridge.getReady(lambda: self.initialised.callback(None), 1079 self.bridge.getReady(lambda: self.initialised.callback(None),
1074 lambda failure: self.initialised.errback(Exception(failure))) 1080 lambda failure: self.initialised.errback(Exception(failure)))
1075 self.initialised.addCallback(backendReady) 1081 self.initialised.addCallback(backendReady)