diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index b4410206..701606fb 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -143,22 +143,9 @@ class IndexHandler(RequestHandler): sickbeard.REMOTE_IP = self.request.remote_ip req_headers = self.request.headers - def delist_arguments(self, args): - """ - Takes a dictionary, 'args' and de-lists any single-item lists then - returns the resulting dictionary. - - In other words, {'foo': ['bar']} would become {'foo': 'bar'} - """ - for arg, value in args.items(): - if len(value) == 1: - args[arg] = value[0] - return args - def _dispatch(self): - args = None - path = self.request.uri.split('?')[0] + path = self.request.uri.replace(sickbeard.WEB_ROOT,'').split('?')[0] method = path.strip('/').split('/')[-1] if path.startswith('/api'): @@ -179,8 +166,10 @@ class IndexHandler(RequestHandler): if klass and not method.startswith('_'): # Sanitize argument lists: - if self.request.arguments: - args = self.delist_arguments(self.request.arguments) + args = self.request.arguments + for arg, value in args.items(): + if len(value) == 1: + args[arg] = value[0] # Regular method handler for classes func = getattr(klass, method, None) @@ -193,30 +182,39 @@ class IndexHandler(RequestHandler): func = getattr(klass, 'index', None) if func: - if args: - return func(**args) - else: - return func() + return func(**args) raise HTTPError(404) def redirect(self, url, permanent=False, status=None): - if not self._transforms: - self._transforms = [] - - super(IndexHandler, self).redirect(url, permanent, status) + self._transforms = [] + super(IndexHandler, self).redirect(sickbeard.WEB_ROOT + url, permanent, status) @asynchronous + @gen.engine def get(self, *args, **kwargs): try: - self.finish(self._dispatch()) + response = yield gen.Task(self.getresponse, self._dispatch) + self.finish(response) except Exception as e: logger.log(ex(e), logger.ERROR) logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG) + @asynchronous + @gen.engine def post(self, *args, **kwargs): - return self._dispatch() - + try: + response = yield gen.Task(self.getresponse, self._dispatch) + self.finish(response) + except Exception as e: + logger.log(ex(e), logger.ERROR) + logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG) + + + def getresponse(self, func, callback): + response = func() + callback(response) + def robots_txt(self, *args, **kwargs): """ Keep web crawlers out """ self.set_header('Content-Type', 'text/plain') @@ -1465,8 +1463,6 @@ class ConfigGeneral(IndexHandler): else: ui.notifications.message('Configuration Saved', ek.ek(os.path.join, sickbeard.CONFIG_FILE)) - self.redirect("/home/") - class ConfigSearch(IndexHandler): def index(self, *args, **kwargs): diff --git a/sickbeard/webserveInit.py b/sickbeard/webserveInit.py index b85319cf..f333d845 100644 --- a/sickbeard/webserveInit.py +++ b/sickbeard/webserveInit.py @@ -12,7 +12,6 @@ from tornado.ioloop import IOLoop server = None - class MultiStaticFileHandler(StaticFileHandler): def initialize(self, paths, default_filename=None): self.paths = paths @@ -101,21 +100,20 @@ def initWebServer(options={}): app = Application([], debug=sickbeard.DEBUG, gzip=True, - xheaders=True, cookie_secret='61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=' ) # Index Handler app.add_handlers(".*$", [ - (r"/", RedirectHandler, {'url': '/home/'}), - (r'/api/(.*)(/?)', webapi.Api), - (r'%s(.*)(/?)' % options['web_root'], webserve.IndexHandler) + (r"/", RedirectHandler, {'url': '%s/home/' % options['web_root']}), + (r'%s/api/(.*)(/?)' % options['web_root'], webapi.Api), + (r'%s/(.*)(/?)' % options['web_root'], webserve.IndexHandler) ]) # Static Path Handler app.add_handlers(".*$", [ - (r'/(favicon\.ico)', MultiStaticFileHandler, - {'paths': '%s/%s' % (options['web_root'], 'images/ico/favicon.ico')}), + (r'%s/(favicon\.ico)' % options['web_root'], MultiStaticFileHandler, + {'paths': [os.path.join(options['data_root'], 'images/ico/favicon.ico')]}), (r'%s/%s/(.*)(/?)' % (options['web_root'], 'images'), MultiStaticFileHandler, {'paths': [os.path.join(options['data_root'], 'images'), os.path.join(sickbeard.CACHE_DIR, 'images'), diff --git a/tornado/web.py b/tornado/web.py index 209b7ecd..96d0572f 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -630,6 +630,7 @@ class RequestHandler(object): self.set_status(status) self.set_header("Location", urlparse.urljoin(utf8(self.request.uri), utf8(url))) + self.finish() def write(self, chunk):