Skip to content

Commit

Permalink
Remove custom JSON dumpoing wit aiohttp - should use python's default
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelyaakoby committed Jul 19, 2024
1 parent 08c1448 commit 30b8931
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions pyctuator/impl/aiohttp_pyctuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,27 @@ class AioHttpPyctuator(PyctuatorRouter):
def __init__(self, app: web.Application, pyctuator_impl: PyctuatorImpl, disabled_endpoints: Endpoints) -> None:
super().__init__(app, pyctuator_impl)

custom_dumps = partial(
json.dumps, default=self._custom_json_serializer
)

async def empty_handler(request: web.Request) -> web.Response:
return web.Response(text='')

async def get_endpoints(request: web.Request) -> web.Response:
return web.json_response(self.get_endpoints_data(), dumps=custom_dumps)
return web.json_response(self.get_endpoints_data)

async def get_environment(request: web.Request) -> web.Response:
return web.json_response(pyctuator_impl.get_environment(), dumps=custom_dumps)
return web.json_response(pyctuator_impl.get_environment)

async def get_info(request: web.Request) -> web.Response:
return web.json_response(pyctuator_impl.get_app_info(), dumps=custom_dumps)
return web.json_response(pyctuator_impl.get_app_info)

async def get_health(request: web.Request) -> web.Response:
health = pyctuator_impl.get_health()
return web.json_response(health, status=health.http_status(), dumps=custom_dumps)
return web.json_response(health, status=health.http_status)

async def get_metric_names(request: web.Request) -> web.Response:
return web.json_response(pyctuator_impl.get_metric_names(), dumps=custom_dumps)
return web.json_response(pyctuator_impl.get_metric_names)

async def get_loggers(request: web.Request) -> web.Response:
return web.json_response(pyctuator_impl.logging.get_loggers(), dumps=custom_dumps)
return web.json_response(pyctuator_impl.logging.get_loggers)

async def set_logger_level(request: web.Request) -> web.Response:
request_dict = await request.json()
Expand All @@ -60,7 +56,7 @@ async def get_logger(request: web.Request) -> web.Response:
return web.json_response(pyctuator_impl.logging.get_logger(logger_name), dumps=custom_dumps)

async def get_thread_dump(request: web.Request) -> web.Response:
return web.json_response(pyctuator_impl.get_thread_dump(), dumps=custom_dumps)
return web.json_response(pyctuator_impl.get_thread_dump)

async def get_httptrace(request: web.Request) -> web.Response:
raw_data = pyctuator_impl.http_tracer.get_httptrace()
Expand Down Expand Up @@ -153,14 +149,6 @@ async def intercept_requests_and_responses(request: web.Request, handler: Callab
app.add_routes(routes)
app.middlewares.append(intercept_requests_and_responses)

def _custom_json_serializer(self, value: Any) -> Any:
if dataclasses.is_dataclass(value):
return dataclasses.asdict(value)

if isinstance(value, datetime):
return str(value)
return None

def _create_headers_dictionary(self, headers: CIMultiDictProxy[str]) -> Mapping[str, List[str]]:
headers_dict: Mapping[str, List[str]] = defaultdict(list)
for (key, value) in headers.items():
Expand Down

0 comments on commit 30b8931

Please sign in to comment.