app: allow http requests to specifiy a websocket id
Some requests, such "printer/objects/subscribe", require a websocket for asynchronous updates. Clients may now specify a "connection_id" in the form data that identifies an associated websocket. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
92d1715d88
commit
5836d60d88
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue