mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-08-27 20:40:13 +03:00
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
This commit is contained in:
parent
a3616e6d33
commit
e27ddf2cdf
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user