Allow non trailing slash API calls
This commit is contained in:
@@ -20,7 +20,8 @@ template_loader = template.Loader(os.path.join(os.path.dirname(__file__), 'templ
|
||||
# Main web handler
|
||||
@requires_auth
|
||||
class WebHandler(RequestHandler):
|
||||
def get(self, route):
|
||||
def get(self, route, *args, **kwargs):
|
||||
route = route.strip('/')
|
||||
if not views.get(route):
|
||||
page_not_found(self)
|
||||
return
|
||||
@@ -55,7 +56,7 @@ addView('docs', apiDocs)
|
||||
|
||||
# Make non basic auth option to get api key
|
||||
class KeyHandler(RequestHandler):
|
||||
def get(self):
|
||||
def get(self, *args, **kwargs):
|
||||
api = None
|
||||
username = Env.setting('username')
|
||||
password = Env.setting('password')
|
||||
|
||||
@@ -14,7 +14,8 @@ class NonBlockHandler(RequestHandler):
|
||||
stoppers = []
|
||||
|
||||
@asynchronous
|
||||
def get(self, route):
|
||||
def get(self, route, *args, **kwargs):
|
||||
route = route.strip('/')
|
||||
start, stop = api_nonblock[route]
|
||||
self.stoppers.append(stop)
|
||||
|
||||
@@ -43,7 +44,8 @@ def addNonBlockApiView(route, func_tuple, docs = None, **kwargs):
|
||||
# Blocking API handler
|
||||
class ApiHandler(RequestHandler):
|
||||
|
||||
def get(self, route):
|
||||
def get(self, route, *args, **kwargs):
|
||||
route = route.strip('/')
|
||||
if not api.get(route):
|
||||
self.write('API call doesn\'t seem to exist')
|
||||
return
|
||||
|
||||
@@ -38,14 +38,3 @@ def requires_auth(handler_class):
|
||||
handler_class._execute = wrap_execute(handler_class._execute)
|
||||
|
||||
return handler_class
|
||||
|
||||
# @wraps(f)
|
||||
# def decorated(*args, **kwargs):
|
||||
# auth = getattr(request, 'authorization')
|
||||
# if Env.setting('username') and Env.setting('password'):
|
||||
# if (not auth or not check_auth(auth.username.decode('latin1'), md5(auth.password.decode('latin1').encode(Env.get('encoding'))))):
|
||||
# return authenticate()
|
||||
#
|
||||
# return f(*args, **kwargs)
|
||||
#
|
||||
# return decorated
|
||||
|
||||
@@ -230,16 +230,15 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
|
||||
|
||||
# Request handlers
|
||||
application.add_handlers(".*$", [
|
||||
(r'%snonblock/(.*)/' % api_base, NonBlockHandler),
|
||||
(r'%snonblock/(.*)(/?)' % api_base, NonBlockHandler),
|
||||
|
||||
# API handlers
|
||||
(r'%s(.*)/' % api_base, ApiHandler), # Main API handler
|
||||
(r'%sgetkey/' % web_base, KeyHandler), # Get API key
|
||||
(r'%s(.*)(/?)' % api_base, ApiHandler), # Main API handler
|
||||
(r'%sgetkey(/?)' % web_base, KeyHandler), # Get API key
|
||||
(r'%s' % api_base, RedirectHandler, {"url": web_base + 'docs/'}), # API docs
|
||||
|
||||
# Catch all webhandlers
|
||||
(r'%s(.*)/' % web_base, WebHandler),
|
||||
(r'%s(.*)' % web_base, WebHandler),
|
||||
(r'%s(.*)(/?)' % web_base, WebHandler),
|
||||
(r'(.*)', WebHandler),
|
||||
])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user