add gzip encoding to responses that are just text

This commit is contained in:
Damien Churchill 2010-01-22 12:39:33 +00:00
parent 2073ae0221
commit 76fcfa498d
4 changed files with 101 additions and 85 deletions

156
ChangeLog
View File

@ -1,108 +1,112 @@
=== Deluge 1.3.0 (In Development) === === Deluge 1.3.0 (In Development) ===
==== Core ==== ==== Core ====
* Implement #1063 option to delete torrent file copy on torrent removal - patch from Ghent * Implement #1063 option to delete torrent file copy on torrent removal - patch from Ghent
* Implement #457 progress bars for folders * Implement #457 progress bars for folders
* Implement #1012 httpdownloader supports gzip decoding * Implement #1012 httpdownloader supports gzip decoding
* #496: Remove deprecated functions in favour of get_session_status() * #496: Remove deprecated functions in favour of get_session_status()
==== 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
* Move to a twisted framework * Move to a twisted framework
* Add an 'Error' filter for Trackers to show trackers that currently have a tracker error * Add an 'Error' filter for Trackers to show trackers that currently have a tracker error
* Use system GeoIP database if available, this is now an optional dependency * Use system GeoIP database if available, this is now an optional dependency
==== GtkUI ==== ==== GtkUI ====
* Remove SignalReceiver * Remove SignalReceiver
* Implemented a cross-platform IPC method thus removing the DBUS dependency * Implemented a cross-platform IPC method thus removing the DBUS dependency
* Implement a "True" Classic Mode where there is no longer a separate daemon process * Implement a "True" Classic Mode where there is no longer a separate daemon process
* Add preferences option "Add torrent in paused state" * Add preferences option "Add torrent in paused state"
* Add tracker icons to the Tracker column * Add tracker icons to the Tracker column
* Implement #259 show tooltip with country name in the peers tab * Implement #259 show tooltip with country name in the peers tab
* Add an error category to the tracker sidebar list * Add an error category to the tracker sidebar list
* Add Find More Plugins button to Plugins preference page * Add Find More Plugins button to Plugins preference page
* Fix #518 remove header in add torrent dialog to save vertical space * Fix #518 remove header in add torrent dialog to save vertical space
* Add a Cache preferences page to adjust cache settings and examine cache status * Add a Cache preferences page to adjust cache settings and examine cache status
* Add ability to rename files prior to adding them * Add ability to rename files prior to adding them
* Fix shutdown handler with GNOME session manager * Fix shutdown handler with GNOME session manager
* Allow 4 MiB piece sizes when creating a torrent * Allow 4 MiB piece sizes when creating a torrent
==== ConsoleUI ==== ==== ConsoleUI ====
* Changed to use curses for a more interactive client * Changed to use curses for a more interactive client
==== WebUI ==== ==== WebUI ====
* Move over to using Twisted-Web for the webserver. * Move over to using Twisted-Web for the webserver.
* Move to only AJAX interface built upon Ext-JS. * Move to only AJAX interface built upon Ext-JS.
==== Plugins ==== ==== Plugins ====
* Add Scheduler plugin * Add Scheduler plugin
* Add Extractor plugin * Add Extractor plugin
==== Misc ==== ==== Misc ====
* PyGTK dependency bumped to => 2.12 to use new tooltip system * PyGTK dependency bumped to => 2.12 to use new tooltip system
* Add new scripts for invoking UIs: deluge-gtk, deluge-web, deluge-console * Add new scripts for invoking UIs: deluge-gtk, deluge-web, deluge-console
* Remove GeoIP database from the source tree * Remove GeoIP database from the source tree
=== Deluge 1.1.0 - "Time gas!" (10 January 2009) === === Deluge 1.1.0 - "Time gas!" (10 January 2009) ===
==== Core ==== ==== Core ====
* Implement #79 ability to change outgoing port range * Implement #79 ability to change outgoing port range
* Implement #296 ability to change peer TOS byte * Implement #296 ability to change peer TOS byte
* Add per-torrent move on completed settings * Add per-torrent move on completed settings
* Implement #414 use async save_resume_data method * Implement #414 use async save_resume_data method
* Filter Manager with torrent filtering in get_torrents_status , for sidebar and plugins. * Filter Manager with torrent filtering in get_torrents_status , for sidebar and plugins.
* Implement #368 add torrents by infohash/magnet uri (trackerless torrents) * Implement #368 add torrents by infohash/magnet uri (trackerless torrents)
* Remove remaining gtk functions in common * Remove remaining gtk functions in common
* Tracker icons. * Tracker icons.
* Add ETA for torrents with stop at seed ratio set * Add ETA for torrents with stop at seed ratio set
* Fix #47 the state and config files are no longer invalidated when there is no diskspace * Fix #47 the state and config files are no longer invalidated when there is no diskspace
* Fix #619 return "" instead of "Infinity" if seconds == 0 in ftime * Fix #619 return "" instead of "Infinity" if seconds == 0 in ftime
* Add -P, --pidfile option to deluged * Add -P, --pidfile option to deluged
==== GtkUI ==== ==== GtkUI ====
* Add peer progress to the peers tab * Add peer progress to the peers tab
* Add ability to manually add peers * Add ability to manually add peers
* Sorting # column will place downloaders above seeds * Sorting # column will place downloaders above seeds
* Remove dependency on libtorrent for add torrent dialog * Remove dependency on libtorrent for add torrent dialog
* Allow adding multiple trackers at once in the edit tracker dialog * Allow adding multiple trackers at once in the edit tracker dialog
* Implement #28 Create Torrent Dialog * Implement #28 Create Torrent Dialog
* Redesiged sidebar with filters for Active and Tracker (see Filter Manager) * Redesiged sidebar with filters for Active and Tracker (see Filter Manager)
* Implement #428 the ability to rename files and directories * Implement #428 the ability to rename files and directories
* Implement #229 add date added column * Implement #229 add date added column
* Implement #596 show speeds in title * Implement #596 show speeds in title
* Fix #636 not setting the daemon's config directory when using --config= with the UI in classic mode. * Fix #636 not setting the daemon's config directory when using --config= with the UI in classic mode.
* Fix #624 do not allow changing file priorities when using compact allocation * Fix #624 do not allow changing file priorities when using compact allocation
* Fix #602 re-did files/peers tab state saving/loading * Fix #602 re-did files/peers tab state saving/loading
* Fix gtk warnings * Fix gtk warnings
* Add protocol traffic statusbar item * Add protocol traffic statusbar item
* Rework the Remove Torrent Dialog to only have 2 options, remove data and remove from session. * Rework the Remove Torrent Dialog to only have 2 options, remove data and remove from session.
* Add "Install Plugin" and "Rescan Plugins" buttons to the Plugins preferences * Add "Install Plugin" and "Rescan Plugins" buttons to the Plugins preferences
* Make active port test use internal graphic instead of launching browser * Make active port test use internal graphic instead of launching browser
==== WebUI ==== ==== WebUI ====
* Lots of smaller tweaks. * Lots of smaller tweaks.
* All details tabs have the same features as in gtk-ui 1.0.x * All details tabs have the same features as in gtk-ui 1.0.x
* Persistent sessions #486 * Persistent sessions #486
* Plugin improvements for easy use of templates and images in eggs. #497 * Plugin improvements for easy use of templates and images in eggs. #497
* Classic template takes over some style elements from white template. * Classic template takes over some style elements from white template.
* https (for users that know how to create certificates) * https (for users that know how to create certificates)
* Easier apache mod_proxy use. * Easier apache mod_proxy use.
* Redesigned sidebar * Redesigned sidebar
==== AjaxUI ==== ==== AjaxUI ====
* Hosted in a webui template. * Hosted in a webui template.
==== ConsoleUI ==== ==== ConsoleUI ====
* New ConsoleUI written by Idoa01 * New ConsoleUI written by Idoa01
* Callable from command-line for scripts. * Callable from command-line for scripts.
==== Plugins ==== ==== Plugins ====
* Stats plugin for graphs. * Stats plugin for graphs.
* Label plugin for grouping torrents and per torrent settings. * Label plugin for grouping torrents and per torrent settings.
==== Misc ==== ==== Misc ====
* Implement #478 display UI options in usage help * Implement #478 display UI options in usage help
* Fix #547 add description to name field per HIG entry 2.1.1.1 * Fix #547 add description to name field per HIG entry 2.1.1.1
* Fix #531 set default log level to ERROR and add 2 command-line options, "-L, --loglevel" and "-q, --quiet". * Fix #531 set default log level to ERROR and add 2 command-line options, "-L, --loglevel" and "-q, --quiet".

View File

@ -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

View File

@ -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()

View File

@ -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>"