Allow non trailing slash API calls
This commit is contained in:
1 parent
74c984dec3
commit
374f8ba1de
4 files changed
+11
-20
No files matched your search
@@ -20,7 +20,8 @@ template_loader = template.Loader(os.path.join(os.path.dirname(__file__), 'templ
|
|||||||
# Main web handler
|
# Main web handler
|
||||||
@requires_auth
|
@requires_auth
|
||||||
class WebHandler(RequestHandler):
|
class WebHandler(RequestHandler):
|
||||||
def get(self, route):
|
def get(self, route, *args, **kwargs):
|
||||||
|
route = route.strip('/')
|
||||||
if not views.get(route):
|
if not views.get(route):
|
||||||
page_not_found(self)
|
page_not_found(self)
|
||||||
return
|
return
|
||||||
@@ -55,7 +56,7 @@ addView('docs', apiDocs)
|
|||||||
|
|
||||||
# Make non basic auth option to get api key
|
# Make non basic auth option to get api key
|
||||||
class KeyHandler(RequestHandler):
|
class KeyHandler(RequestHandler):
|
||||||
def get(self):
|
def get(self, *args, **kwargs):
|
||||||
api = None
|
api = None
|
||||||
username = Env.setting('username')
|
username = Env.setting('username')
|
||||||
password = Env.setting('password')
|
password = Env.setting('password')
|
||||||
|
|||||||
+4
-2
@@ -14,7 +14,8 @@ class NonBlockHandler(RequestHandler):
|
|||||||
stoppers = []
|
stoppers = []
|
||||||
|
|
||||||
@asynchronous
|
@asynchronous
|
||||||
def get(self, route):
|
def get(self, route, *args, **kwargs):
|
||||||
|
route = route.strip('/')
|
||||||
start, stop = api_nonblock[route]
|
start, stop = api_nonblock[route]
|
||||||
self.stoppers.append(stop)
|
self.stoppers.append(stop)
|
||||||
|
|
||||||
@@ -43,7 +44,8 @@ def addNonBlockApiView(route, func_tuple, docs = None, **kwargs):
|
|||||||
# Blocking API handler
|
# Blocking API handler
|
||||||
class ApiHandler(RequestHandler):
|
class ApiHandler(RequestHandler):
|
||||||
|
|
||||||
def get(self, route):
|
def get(self, route, *args, **kwargs):
|
||||||
|
route = route.strip('/')
|
||||||
if not api.get(route):
|
if not api.get(route):
|
||||||
self.write('API call doesn\'t seem to exist')
|
self.write('API call doesn\'t seem to exist')
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -38,14 +38,3 @@ def requires_auth(handler_class):
|
|||||||
handler_class._execute = wrap_execute(handler_class._execute)
|
handler_class._execute = wrap_execute(handler_class._execute)
|
||||||
|
|
||||||
return handler_class
|
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
|
# Request handlers
|
||||||
application.add_handlers(".*$", [
|
application.add_handlers(".*$", [
|
||||||
(r'%snonblock/(.*)/' % api_base, NonBlockHandler),
|
(r'%snonblock/(.*)(/?)' % api_base, NonBlockHandler),
|
||||||
|
|
||||||
# API handlers
|
# API handlers
|
||||||
(r'%s(.*)/' % api_base, ApiHandler), # Main API handler
|
(r'%s(.*)(/?)' % api_base, ApiHandler), # Main API handler
|
||||||
(r'%sgetkey/' % web_base, KeyHandler), # Get API key
|
(r'%sgetkey(/?)' % web_base, KeyHandler), # Get API key
|
||||||
(r'%s' % api_base, RedirectHandler, {"url": web_base + 'docs/'}), # API docs
|
(r'%s' % api_base, RedirectHandler, {"url": web_base + 'docs/'}), # API docs
|
||||||
|
|
||||||
# Catch all webhandlers
|
# Catch all webhandlers
|
||||||
(r'%s(.*)/' % web_base, WebHandler),
|
(r'%s(.*)(/?)' % web_base, WebHandler),
|
||||||
(r'%s(.*)' % web_base, WebHandler),
|
|
||||||
(r'(.*)', WebHandler),
|
(r'(.*)', WebHandler),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user