]> git.ipfire.org Git - pakfire.git/commitdiff
hub: Add support for POST requests
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 May 2022 11:57:15 +0000 (11:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 May 2022 11:57:15 +0000 (11:57 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/hub.py

index e47a1db88d385be931ac14e7d0bc0266b3ca115d..cccd532a5c2c4ab47044209a4c741a9da8933c1e 100644 (file)
@@ -52,17 +52,25 @@ class Hub(object):
 
                # XXX support proxies
 
-       async def _request(self, method, path, body_producer=None, **kwargs):
+       async def _request(self, method, path, body=None, body_producer=None, **kwargs):
                # Make absolute URL
                url = urllib.parse.urljoin(self.url, path)
 
+               # Convert any query arguments
+               query_args = urllib.parse.urlencode(kwargs)
+
                # Add query arguments
                if method in ("GET", "PUT"):
-                       url = "%s?%s" % (url, urllib.parse.urlencode(kwargs))
+                       url = "%s?%s" % (url, query_args)
+
+               # Add any arguments to the body
+               elif method == "POST":
+                       if body is None:
+                               body = query_args
 
                # Make the request
                req = tornado.httpclient.HTTPRequest(
-                       method=method, url=url,
+                       method=method, url=url, body=body,
 
                        # Authentication
                        auth_username=self.username, auth_password=self.password,