summaryrefslogtreecommitdiffstats
path: root/module/web
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-06-09 20:20:08 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-06-09 20:20:08 +0200
commitdef4fb88277aa00f41104b5bfac8239ba4341373 (patch)
tree6fd30426aa91b7e28e420c7ab6d8374b0e14a7a6 /module/web
parentbottle.py update (diff)
downloadpyload-def4fb88277aa00f41104b5bfac8239ba4341373.tar.xz
new supported webserver (lightweight)
Diffstat (limited to 'module/web')
-rw-r--r--module/web/ServerThread.py22
-rw-r--r--module/web/middlewares.py6
-rw-r--r--module/web/utils.py4
-rw-r--r--module/web/webinterface.py4
4 files changed, 32 insertions, 4 deletions
diff --git a/module/web/ServerThread.py b/module/web/ServerThread.py
index b343b6526..d4992572d 100644
--- a/module/web/ServerThread.py
+++ b/module/web/ServerThread.py
@@ -47,18 +47,30 @@ class WebServer(threading.Thread):
log.warning(_("Can't use %(server)s, python-flup is not installed!") % {
"server": self.server})
self.server = "builtin"
+ elif self.server == "lightweight":
+ try:
+ import bjoern
+ except Exception, e:
+ log.error(_("Error importing lightweight server: %s") % e)
+ log.warning(_("You need to download and compile bjoern, https://github.com/jonashaag/bjoern"))
+ log.warning(_("Copy the boern.so to module/lib folder or use setup.py install"))
+ log.warning(_("Of course you need to be familiar with linux and know how to compile software"))
+ log.warning(_("in order to do this, but its worth the effort."))
+ self.server = "builtin"
if self.server == "fastcgi":
self.start_fcgi()
elif self.server == "threaded":
self.start_threaded()
+ elif self.server == "lightweight":
+ self.start_lightweight()
else:
self.start_builtin()
def start_builtin(self):
if self.https:
- log.warning(_("The simple builtin server offers no SSL, please consider using threaded instead"))
+ log.warning(_("This server offers no SSL, please consider using threaded instead"))
self.core.log.info(_("Starting builtin webserver: %(host)s:%(port)d") % {"host": self.host, "port": self.port})
webinterface.run_simple(host=self.host, port=self.port)
@@ -78,5 +90,13 @@ class WebServer(threading.Thread):
self.core.log.info(_("Starting fastcgi server: %(host)s:%(port)d") % {"host": self.host, "port": self.port})
webinterface.run_fcgi(host=self.host, port=self.port)
+
+ def start_lightweight(self):
+ if self.https:
+ log.warning(_("This server offers no SSL, please consider using threaded instead"))
+
+ self.core.log.info(_("Starting lightweight webserver (bjoern): %(host)s:%(port)d") % {"host": self.host, "port": self.port})
+ webinterface.run_lightweight(host=self.host, port=self.port)
+
def quit(self):
self.running = False
diff --git a/module/web/middlewares.py b/module/web/middlewares.py
index b71138e69..a4b962988 100644
--- a/module/web/middlewares.py
+++ b/module/web/middlewares.py
@@ -123,7 +123,11 @@ class GzipResponse(object):
output.close()
finally:
if hasattr(app_iter, 'close'):
- app_iter.close()
+ try:
+ app_iter.close()
+ except :
+ pass
+
content_length = self.buffer.tell()
update_header(self.headers, "Content-Length" , str(content_length))
self.start_response(self.status, self.headers) \ No newline at end of file
diff --git a/module/web/utils.py b/module/web/utils.py
index fccfb78d6..81baa4fd2 100644
--- a/module/web/utils.py
+++ b/module/web/utils.py
@@ -93,14 +93,14 @@ def login_required(perm=None):
if perm:
perms = parse_permissions(s)
if not perms.has_key(perm) or not perms[perm]:
- if request.header.get('X-Requested-With') == 'XMLHttpRequest':
+ if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
return HTTPError(403, "Forbidden")
else:
return redirect("/nopermission")
return func(*args, **kwargs)
else:
- if request.header.get('X-Requested-With') == 'XMLHttpRequest':
+ if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
return HTTPError(403, "Forbidden")
else:
return redirect("/login")
diff --git a/module/web/webinterface.py b/module/web/webinterface.py
index 387a2cbbf..17be5c3b3 100644
--- a/module/web/webinterface.py
+++ b/module/web/webinterface.py
@@ -98,6 +98,7 @@ session_opts = {
web = StripPathMiddleware(SessionMiddleware(app(), session_opts))
web = GZipMiddleWare(web)
+#install(otfcompress)
import pyload_app
import json_app
@@ -106,6 +107,9 @@ import cnl_app
def run_simple(host="0.0.0.0", port="8000"):
run(app=web, host=host, port=port, quiet=True)
+def run_lightweight(host="0.0.0.0", port="8000"):
+ run(app=web, host=host, port=port, quiet=True, server="bjoern")
+
def run_threaded(host="0.0.0.0", port="8000", theads=3, cert="", key=""):
from wsgiserver import CherryPyWSGIServer
if cert and key: