]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: HTTP API: fixed returning Python str() instead of json.dumps()
authorVasek Sraier <git@vakabus.cz>
Thu, 22 Dec 2022 10:55:48 +0000 (11:55 +0100)
committerVasek Sraier <git@vakabus.cz>
Thu, 22 Dec 2022 11:14:56 +0000 (12:14 +0100)
manager/knot_resolver_manager/server.py
manager/knot_resolver_manager/utils/modeling/query.py

index 175d522aa426f9f90d58f6ecd86c73b88599886f..f0b8af5979cb5e0158e25dab6a613a2ae4ad496e 100644 (file)
@@ -1,5 +1,6 @@
 import asyncio
 import errno
+import json
 import logging
 import os
 import signal
@@ -206,8 +207,10 @@ class Server:
             # apply
             await self.config_store.update(config_validated)
 
-        # return success
-        resp_text: Optional[str] = str(to_return) if to_return is not None else None
+        # serialize the response (the `to_return` object is a Dict/list/scalar, we want to return json)
+        resp_text: Optional[str] = json.dumps(to_return) if to_return is not None else None
+
+        # create the response and return it
         res = web.Response(status=HTTPStatus.OK, text=resp_text, content_type="application/json")
         res.headers.add("ETag", f'"{structural_etag(new_config)}"')
         return res
index b63e4b9682290763b89d1641977bc0878755055c..bff51cabb6c0ac3084dfadbccdccd5c7dfdc989a 100644 (file)
@@ -136,11 +136,6 @@ class TestOp(Op):
 def query(
     original: Any, method: Literal["get", "delete", "put", "patch"], ptr: str, payload: Any
 ) -> Tuple[Any, Optional[Any]]:
-    """
-    Implements a modification API in the style of Caddy:
-        https://caddyserver.com/docs/api
-    """
-
     ########################################
     # Prepare data we will be working on