From: Michael Tremer Date: Thu, 26 May 2022 15:14:03 +0000 (+0000) Subject: hub: Add websocket capability X-Git-Tag: 0.9.28~741 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24763c22cfb85de04a170d56b6cab26b921703b4;p=pakfire.git hub: Add websocket capability Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/hub.py b/src/pakfire/hub.py index 95d2ad002..be5a509e3 100644 --- a/src/pakfire/hub.py +++ b/src/pakfire/hub.py @@ -27,6 +27,7 @@ import logging import os.path import psutil import tornado.httpclient +import tornado.websocket import urllib.parse from . import _pakfire @@ -55,10 +56,15 @@ class Hub(object): # XXX support proxies - async def _request(self, method, path, body=None, body_producer=None, **kwargs): + async def _request(self, method, path, websocket=False, + body=None, body_producer=None, on_message_callback=None, **kwargs): # Make absolute URL url = urllib.parse.urljoin(self.url, path) + # Change scheme for websocket + if websocket and url.startswith("https://"): + url = url.replace("https://", "wss://") + # Convert any query arguments query_args = urllib.parse.urlencode(kwargs) @@ -82,6 +88,13 @@ class Hub(object): body_producer=body_producer, ) + # Is this a web socket request? + if websocket: + return await tornado.websocket.websocket_connect( + req, + on_message_callback=on_message_callback, + ) + # Send the request and wait for a response res = await self.client.fetch(req)