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)
|
self.registered_base_handlers.append(api_def.uri)
|
||||||
|
|
||||||
def register_local_handler(self, uri, request_methods,
|
def register_local_handler(self, uri, request_methods,
|
||||||
callback, http_only=False):
|
callback, protocol=["http", "websocket"]):
|
||||||
if uri in self.registered_base_handlers:
|
if uri in self.registered_base_handlers:
|
||||||
return
|
return
|
||||||
api_def = self._create_api_definition(
|
api_def = self._create_api_definition(
|
||||||
uri, request_methods, is_remote=False)
|
uri, request_methods, is_remote=False)
|
||||||
msg = "Registering local endpoint - "
|
msg = "Registering local endpoint"
|
||||||
msg += f"HTTP: ({' '.join(request_methods)}) {uri}"
|
if "http" in protocol:
|
||||||
if not http_only:
|
msg += f" - HTTP: ({' '.join(request_methods)}) {uri}"
|
||||||
msg += f"; Websocket: {', '.join(api_def.ws_methods)}"
|
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)
|
self.wsm.register_local_handler(api_def, callback)
|
||||||
logging.info(msg)
|
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,
|
def register_static_file_handler(self, pattern, file_path,
|
||||||
can_delete=False, op_check_cb=None):
|
can_delete=False, op_check_cb=None):
|
||||||
|
|
|
@ -66,10 +66,10 @@ class Authorization:
|
||||||
# Register Authorization Endpoints
|
# Register Authorization Endpoints
|
||||||
app.register_local_handler(
|
app.register_local_handler(
|
||||||
"/access/api_key", ['GET', 'POST'],
|
"/access/api_key", ['GET', 'POST'],
|
||||||
self._handle_apikey_request, http_only=True)
|
self._handle_apikey_request, protocol=['http'])
|
||||||
app.register_local_handler(
|
app.register_local_handler(
|
||||||
"/access/oneshot_token", ['GET'],
|
"/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):
|
async def _handle_apikey_request(self, path, method, args):
|
||||||
if method.upper() == 'POST':
|
if method.upper() == 'POST':
|
||||||
|
|
Loading…
Reference in New Issue