app: allow local handlers to select their supported protocol
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
c523f35c5e
commit
059f5d6a73
|
@ -165,25 +165,26 @@ class MoonrakerApp:
|
|||
self.registered_base_handlers.append(api_def.uri)
|
||||
|
||||
def register_local_handler(self, uri, request_methods,
|
||||
callback, http_only=False):
|
||||
callback, protocol=["http", "websocket"]):
|
||||
if uri in self.registered_base_handlers:
|
||||
return
|
||||
api_def = self._create_api_definition(
|
||||
uri, request_methods, is_remote=False)
|
||||
msg = "Registering local endpoint - "
|
||||
msg += f"HTTP: ({' '.join(request_methods)}) {uri}"
|
||||
if not http_only:
|
||||
msg += f"; Websocket: {', '.join(api_def.ws_methods)}"
|
||||
msg = "Registering local endpoint"
|
||||
if "http" in protocol:
|
||||
msg += f" - HTTP: ({' '.join(request_methods)}) {uri}"
|
||||
params = {}
|
||||
params['server'] = self.server
|
||||
params['auth'] = self.auth
|
||||
params['methods'] = request_methods
|
||||
params['arg_parser'] = api_def.parser
|
||||
params['callback'] = callback
|
||||
self.mutable_router.add_handler(uri, LocalRequestHandler, params)
|
||||
self.registered_base_handlers.append(uri)
|
||||
if "websocket" in protocol:
|
||||
msg += f" - Websocket: {', '.join(api_def.ws_methods)}"
|
||||
self.wsm.register_local_handler(api_def, callback)
|
||||
logging.info(msg)
|
||||
params = {}
|
||||
params['server'] = self.server
|
||||
params['auth'] = self.auth
|
||||
params['methods'] = request_methods
|
||||
params['arg_parser'] = api_def.parser
|
||||
params['callback'] = callback
|
||||
self.mutable_router.add_handler(uri, LocalRequestHandler, params)
|
||||
self.registered_base_handlers.append(uri)
|
||||
|
||||
def register_static_file_handler(self, pattern, file_path,
|
||||
can_delete=False, op_check_cb=None):
|
||||
|
|
|
@ -66,10 +66,10 @@ class Authorization:
|
|||
# Register Authorization Endpoints
|
||||
app.register_local_handler(
|
||||
"/access/api_key", ['GET', 'POST'],
|
||||
self._handle_apikey_request, http_only=True)
|
||||
self._handle_apikey_request, protocol=['http'])
|
||||
app.register_local_handler(
|
||||
"/access/oneshot_token", ['GET'],
|
||||
self._handle_token_request, http_only=True)
|
||||
self._handle_token_request, protocol=['http'])
|
||||
|
||||
async def _handle_apikey_request(self, path, method, args):
|
||||
if method.upper() == 'POST':
|
||||
|
|
Loading…
Reference in New Issue