diff --git a/moonraker/app.py b/moonraker/app.py index fbd5acb..11b39b2 100644 --- a/moonraker/app.py +++ b/moonraker/app.py @@ -270,12 +270,13 @@ class RemoteRequestHandler(AuthorizedRequestHandler): await self._process_http_request() async def _process_http_request(self): + conn = self.get_associated_websocket() args = {} if self.request.query: args = self.query_parser(self.request) try: result = await self.server.make_request( - WebRequest(self.remote_callback, args)) + WebRequest(self.remote_callback, args, conn=conn)) except ServerError as e: raise tornado.web.HTTPError( e.status_code, str(e)) from e @@ -307,12 +308,13 @@ class LocalRequestHandler(AuthorizedRequestHandler): raise tornado.web.HTTPError(405) async def _process_http_request(self, method): + conn = self.get_associated_websocket() args = {} if self.request.query: args = self.query_parser(self.request) try: result = await self.callback( - WebRequest(self.request.path, args, method)) + WebRequest(self.request.path, args, method, conn=conn)) except ServerError as e: raise tornado.web.HTTPError( e.status_code, str(e)) from e diff --git a/moonraker/authorization.py b/moonraker/authorization.py index 087ce06..14aa76c 100644 --- a/moonraker/authorization.py +++ b/moonraker/authorization.py @@ -208,6 +208,20 @@ class AuthorizedRequestHandler(tornado.web.RequestHandler): else: super(AuthorizedRequestHandler, self).options() + def get_associated_websocket(self): + # Return associated websocket connection if an id + # was provided by the request + conn = None + conn_id = self.get_argument('connection_id', None) + if conn_id is not None: + try: + conn_id = int(conn_id) + except Exception: + pass + else: + conn = self.wsm.get_websocket(conn_id) + return conn + # Due to the way Python treats multiple inheritance its best # to create a separate authorized handler for serving files class AuthorizedFileHandler(tornado.web.StaticFileHandler):