import os.path
import psutil
import tornado.httpclient
+import tornado.websocket
import urllib.parse
from . import _pakfire
# 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)
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)