add gzip encoding to responses that are just text
This commit is contained in:
parent
2073ae0221
commit
76fcfa498d
|
@ -8,6 +8,10 @@
|
||||||
==== Blocklist ====
|
==== Blocklist ====
|
||||||
* Implement local blocklist support
|
* Implement local blocklist support
|
||||||
|
|
||||||
|
==== Web ====
|
||||||
|
* Migrate to ExtJS 3.1
|
||||||
|
* Add gzip compression of HTTP data to the server
|
||||||
|
|
||||||
=== Deluge 1.2.0 - "Bursting like an infected kidney" (10 January 2010) ===
|
=== Deluge 1.2.0 - "Bursting like an infected kidney" (10 January 2010) ===
|
||||||
==== Core ====
|
==== Core ====
|
||||||
* Implement new RPC protocol DelugeRPC replacing XMLRPC
|
* Implement new RPC protocol DelugeRPC replacing XMLRPC
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import zlib
|
||||||
import gettext
|
import gettext
|
||||||
from mako.template import Template as MakoTemplate
|
from mako.template import Template as MakoTemplate
|
||||||
from deluge import common
|
from deluge import common
|
||||||
|
@ -50,6 +51,14 @@ def escape(text):
|
||||||
text = text.replace('\n', '\\n')
|
text = text.replace('\n', '\\n')
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
def compress(contents, request):
|
||||||
|
request.setHeader("content-encoding", "gzip")
|
||||||
|
compress = zlib.compressobj(6, zlib.DEFLATED, zlib.MAX_WBITS + 16,
|
||||||
|
zlib.DEF_MEM_LEVEL,0)
|
||||||
|
contents = compress.compress(contents)
|
||||||
|
contents += compress.flush()
|
||||||
|
return contents
|
||||||
|
|
||||||
class Template(MakoTemplate):
|
class Template(MakoTemplate):
|
||||||
"""
|
"""
|
||||||
A template that adds some built-ins to the rendering
|
A template that adds some built-ins to the rendering
|
||||||
|
|
|
@ -51,7 +51,7 @@ from deluge.ui import common as uicommon
|
||||||
from deluge.ui.client import client, Client
|
from deluge.ui.client import client, Client
|
||||||
from deluge.ui.coreconfig import CoreConfig
|
from deluge.ui.coreconfig import CoreConfig
|
||||||
|
|
||||||
from deluge.ui.web.common import _
|
from deluge.ui.web.common import _, compress
|
||||||
json = common.json
|
json = common.json
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -257,7 +257,7 @@ class JSON(resource.Resource, component.Component):
|
||||||
def _send_response(self, request, response):
|
def _send_response(self, request, response):
|
||||||
response = json.dumps(response)
|
response = json.dumps(response)
|
||||||
request.setHeader("content-type", "application/x-json")
|
request.setHeader("content-type", "application/x-json")
|
||||||
request.write(response)
|
request.write(compress(response, request))
|
||||||
request.finish()
|
request.finish()
|
||||||
|
|
||||||
def render(self, request):
|
def render(self, request):
|
||||||
|
@ -490,11 +490,14 @@ class WebApi(JSONComponent):
|
||||||
|
|
||||||
def got_torrents(torrents):
|
def got_torrents(torrents):
|
||||||
ui_info["torrents"] = torrents
|
ui_info["torrents"] = torrents
|
||||||
|
for id in torrents:
|
||||||
|
torrent = torrents[id]
|
||||||
|
torrent["id"] = id
|
||||||
|
|
||||||
def on_complete(result):
|
def on_complete(result):
|
||||||
d.callback(ui_info)
|
d.callback(ui_info)
|
||||||
|
|
||||||
d1 = client.core.get_torrents_status(filter_dict, keys)
|
d1 = client.core.get_torrents_status({}, keys)
|
||||||
d1.addCallback(got_torrents)
|
d1.addCallback(got_torrents)
|
||||||
|
|
||||||
d2 = client.core.get_filter_tree()
|
d2 = client.core.get_filter_tree()
|
||||||
|
|
|
@ -56,7 +56,7 @@ from deluge.log import setupLogger, LOG as _log
|
||||||
from deluge.ui import common as uicommon
|
from deluge.ui import common as uicommon
|
||||||
from deluge.ui.tracker_icons import TrackerIcons
|
from deluge.ui.tracker_icons import TrackerIcons
|
||||||
from deluge.ui.web.auth import Auth
|
from deluge.ui.web.auth import Auth
|
||||||
from deluge.ui.web.common import Template
|
from deluge.ui.web.common import Template, compress
|
||||||
from deluge.ui.web.json_api import JSON, WebApi
|
from deluge.ui.web.json_api import JSON, WebApi
|
||||||
from deluge.ui.web.pluginmanager import PluginManager
|
from deluge.ui.web.pluginmanager import PluginManager
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -129,17 +129,17 @@ class Config(resource.Resource):
|
||||||
def render(self, request):
|
def render(self, request):
|
||||||
web_config = component.get("Web").get_config()
|
web_config = component.get("Web").get_config()
|
||||||
config = dict([(key, web_config[key]) for key in UI_CONFIG_KEYS])
|
config = dict([(key, web_config[key]) for key in UI_CONFIG_KEYS])
|
||||||
return """Deluge = {
|
return compress("""Deluge = {
|
||||||
author: 'Damien Churchill <damoxc@gmail.com>',
|
author: 'Damien Churchill <damoxc@gmail.com>',
|
||||||
version: '1.2-dev',
|
version: '1.2-dev',
|
||||||
config: %s
|
config: %s
|
||||||
}""" % common.json.dumps(config)
|
}""" % common.json.dumps(config), request)
|
||||||
|
|
||||||
class GetText(resource.Resource):
|
class GetText(resource.Resource):
|
||||||
def render(self, request):
|
def render(self, request):
|
||||||
request.setHeader("content-type", "text/javascript; encoding=utf-8")
|
request.setHeader("content-type", "text/javascript; encoding=utf-8")
|
||||||
template = Template(filename=rpath("gettext.js"))
|
template = Template(filename=rpath("gettext.js"))
|
||||||
return template.render()
|
return compress(template.render(), request)
|
||||||
|
|
||||||
class Upload(resource.Resource):
|
class Upload(resource.Resource):
|
||||||
"""
|
"""
|
||||||
|
@ -196,7 +196,7 @@ class Render(resource.Resource):
|
||||||
template = Template(filename=rpath(filename))
|
template = Template(filename=rpath(filename))
|
||||||
request.setHeader("content-type", "text/html")
|
request.setHeader("content-type", "text/html")
|
||||||
request.setResponseCode(http.OK)
|
request.setResponseCode(http.OK)
|
||||||
return template.render()
|
return compress(template.render(), request)
|
||||||
|
|
||||||
class Tracker(resource.Resource):
|
class Tracker(resource.Resource):
|
||||||
tracker_icons = TrackerIcons()
|
tracker_icons = TrackerIcons()
|
||||||
|
@ -285,7 +285,7 @@ class LookupResource(resource.Resource, component.Component):
|
||||||
log.debug("Serving path: '%s'", path)
|
log.debug("Serving path: '%s'", path)
|
||||||
mime_type = mimetypes.guess_type(path)
|
mime_type = mimetypes.guess_type(path)
|
||||||
request.setHeader("content-type", mime_type[0])
|
request.setHeader("content-type", mime_type[0])
|
||||||
return open(path, "rb").read()
|
return compress(open(path, "rb").read(), request)
|
||||||
|
|
||||||
request.setResponseCode(http.NOT_FOUND)
|
request.setResponseCode(http.NOT_FOUND)
|
||||||
return "<h1>404 - Not Found</h1>"
|
return "<h1>404 - Not Found</h1>"
|
||||||
|
|
Loading…
Reference in New Issue