From e27ddf2cdf3c8b9d645de9d502a453abd5aef6b0 Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Sun, 22 Feb 2026 23:43:47 +0800 Subject: [PATCH] feat(api): fix ETag handling and JSON serialization in template endpoint - Use `default=str` in `json.dumps` to handle non-serializable objects - Return proper HTTP 304 response with ETag header instead of raising exception - Ensure consistent ETag generation for template caching --- gns3server/api/routes/controller/templates.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gns3server/api/routes/controller/templates.py b/gns3server/api/routes/controller/templates.py index 4594fd635..edaf9692d 100644 --- a/gns3server/api/routes/controller/templates.py +++ b/gns3server/api/routes/controller/templates.py @@ -88,10 +88,10 @@ async def get_template( request_etag = request.headers.get("If-None-Match", "") template = await TemplatesService(templates_repo).get_template(template_id) - data = json.dumps(template) + data = json.dumps(template, default=str) template_etag = '"' + hashlib.md5(data.encode()).hexdigest() + '"' if template_etag == request_etag: - raise HTTPException(status_code=status.HTTP_304_NOT_MODIFIED) + return Response(status_code=status.HTTP_304_NOT_MODIFIED, headers={"ETag": template_etag}) else: response.headers["ETag"] = template_etag return template