app: include all arguments in parsers

Clients may provide arguments either in the query string or body.  Reserved arguments "token" and "connection_id" are excluded from the result.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-11-10 08:47:14 -05:00
parent 5836d60d88
commit daa93b0a2f
1 changed files with 22 additions and 22 deletions

View File

@ -23,29 +23,33 @@ RESERVED_ENDPOINTS = [
"register_remote_method" "register_remote_method"
] ]
EXCLUDED_ARGS = ["_", "token", "connection_id"]
# Status objects require special parsing # Status objects require special parsing
def _status_parser(request): def _status_parser(request_handler):
query_args = request.query_arguments request = request_handler.request
arg_list = request.arguments.keys()
args = {} args = {}
for key, vals in query_args.items(): for key in arg_list:
parsed = [] if key in EXCLUDED_ARGS:
for v in vals: continue
if v: val = request_handler.get_argument(key)
parsed += v.decode().split(',') if not val:
if parsed == []: args[key] = None
parsed = None else:
args[key] = parsed args[key] = val.split(',')
logging.debug(f"Parsed Arguments: {args}")
return {'objects': args} return {'objects': args}
# Built-in Query String Parser # Built-in Query String Parser
def _default_parser(request): def _default_parser(request_handler):
query_args = request.query_arguments request = request_handler.request
arg_list = request.arguments.keys()
args = {} args = {}
for key, vals in query_args.items(): for key in arg_list:
if len(vals) != 1: if key in EXCLUDED_ARGS:
raise tornado.web.HTTPError(404, "Invalid Query String") continue
args[key] = vals[0].decode() args[key] = request_handler.get_argument(key)
return args return args
class MutableRouter(tornado.web.ReversibleRuleRouter): class MutableRouter(tornado.web.ReversibleRuleRouter):
@ -271,9 +275,7 @@ class RemoteRequestHandler(AuthorizedRequestHandler):
async def _process_http_request(self): async def _process_http_request(self):
conn = self.get_associated_websocket() conn = self.get_associated_websocket()
args = {} args = self.query_parser(self)
if self.request.query:
args = self.query_parser(self.request)
try: try:
result = await self.server.make_request( result = await self.server.make_request(
WebRequest(self.remote_callback, args, conn=conn)) WebRequest(self.remote_callback, args, conn=conn))
@ -309,9 +311,7 @@ class LocalRequestHandler(AuthorizedRequestHandler):
async def _process_http_request(self, method): async def _process_http_request(self, method):
conn = self.get_associated_websocket() conn = self.get_associated_websocket()
args = {} args = self.query_parser(self)
if self.request.query:
args = self.query_parser(self.request)
try: try:
result = await self.callback( result = await self.callback(
WebRequest(self.request.path, args, method, conn=conn)) WebRequest(self.request.path, args, method, conn=conn))