TG1 server.webpath mechanics makes it impossible to use a filter on the controller itself. So we put it on the root controller and carrefully change the WSRoot webpath so that everything works properly
This commit is contained in:
parent
f4884b3480
commit
8083ba94c3
@ -105,9 +105,9 @@ class WSRoot(object):
|
|||||||
def _select_protocol(self, request):
|
def _select_protocol(self, request):
|
||||||
log.debug("Selecting a protocol for the following request :\n"
|
log.debug("Selecting a protocol for the following request :\n"
|
||||||
"headers: %s\nbody: %s", request.headers,
|
"headers: %s\nbody: %s", request.headers,
|
||||||
len(request.body) > 512
|
request.body and (len(request.body) > 512
|
||||||
and request.body[:512]
|
and request.body[:512]
|
||||||
or request.body)
|
or request.body) or '')
|
||||||
protocol = None
|
protocol = None
|
||||||
if 'wsmeproto' in request.params:
|
if 'wsmeproto' in request.params:
|
||||||
return self._get_protocol(request.params['wsmeproto'])
|
return self._get_protocol(request.params['wsmeproto'])
|
||||||
@ -173,6 +173,7 @@ class WSRoot(object):
|
|||||||
protocol = self._select_protocol(request)
|
protocol = self._select_protocol(request)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
msg = ("Error while selecting protocol: %s" % str(e))
|
msg = ("Error while selecting protocol: %s" % str(e))
|
||||||
|
log.exception(msg)
|
||||||
protocol = None
|
protocol = None
|
||||||
|
|
||||||
if protocol is None:
|
if protocol is None:
|
||||||
|
31
wsme/tg1.py
31
wsme/tg1.py
@ -1,17 +1,22 @@
|
|||||||
import cherrypy
|
import cherrypy
|
||||||
from cherrypy.filters.basefilter import BaseFilter
|
from cherrypy.filters.basefilter import BaseFilter
|
||||||
import webob
|
import webob
|
||||||
from turbogears import expose
|
from turbogears import expose, config
|
||||||
|
from turbogears.startup import call_on_startup, call_on_shutdown
|
||||||
|
|
||||||
|
|
||||||
class WSMECherrypyFilter(BaseFilter):
|
class WSMECherrypyFilter(BaseFilter):
|
||||||
|
def __init__(self, controller):
|
||||||
|
self.controller = controller
|
||||||
|
self.webpath = None
|
||||||
|
|
||||||
def on_start_resource(self):
|
def on_start_resource(self):
|
||||||
cherrypy.request.processRequestBody = False
|
path = cherrypy.request.path
|
||||||
|
if path.startswith(self.controller._wsroot._webpath):
|
||||||
|
cherrypy.request.processRequestBody = False
|
||||||
|
|
||||||
|
|
||||||
class Controller(object):
|
class Controller(object):
|
||||||
_cp_filters = [WSMECherrypyFilter()]
|
|
||||||
|
|
||||||
def __init__(self, wsroot):
|
def __init__(self, wsroot):
|
||||||
self._wsroot = wsroot
|
self._wsroot = wsroot
|
||||||
|
|
||||||
@ -25,4 +30,20 @@ class Controller(object):
|
|||||||
|
|
||||||
|
|
||||||
def adapt(wsroot):
|
def adapt(wsroot):
|
||||||
return Controller(wsroot)
|
controller = Controller(wsroot)
|
||||||
|
filter_ = WSMECherrypyFilter(controller)
|
||||||
|
|
||||||
|
def install_filter():
|
||||||
|
filter_.webpath = config.get('server.webpath') or ''
|
||||||
|
controller._wsroot._webpath = \
|
||||||
|
filter_.webpath + controller._wsroot._webpath
|
||||||
|
cherrypy.root._cp_filters.append(filter_)
|
||||||
|
|
||||||
|
def uninstall_filter():
|
||||||
|
cherrypy.root._cp_filters.remove(filter_)
|
||||||
|
controller._wsroot._webpath = \
|
||||||
|
controller._wsroot._webpath[len(filter_.webpath):]
|
||||||
|
|
||||||
|
call_on_startup.append(install_filter)
|
||||||
|
call_on_shutdown.append(uninstall_filter)
|
||||||
|
return controller
|
||||||
|
Loading…
x
Reference in New Issue
Block a user