Fix Content-Disposition header to comply with RFC 2183

The /view endpoint set Content-Disposition to bare `filename="..."`
without a disposition-type, which violates RFC 2183/6266 grammar.
Strict parsers (e.g. Go's mime.ParseMediaType) reject the header
outright, preventing third-party tools from extracting the filename.
Adding the `attachment;` disposition-type makes the header
spec-compliant.

Fixes #8914
This commit is contained in:
nahcmon 2026-06-08 18:26:14 +02:00
parent 38f750d80e
commit 9d98181653

View File

@ -560,7 +560,7 @@ class PromptServer():
buffer.seek(0) buffer.seek(0)
return web.Response(body=buffer.read(), content_type=f'image/{image_format}', return web.Response(body=buffer.read(), content_type=f'image/{image_format}',
headers={"Content-Disposition": f"filename=\"{filename}\""}) headers={"Content-Disposition": f"attachment; filename=\"{filename}\""})
if 'channel' not in request.rel_url.query: if 'channel' not in request.rel_url.query:
channel = 'rgba' channel = 'rgba'
@ -580,7 +580,7 @@ class PromptServer():
buffer.seek(0) buffer.seek(0)
return web.Response(body=buffer.read(), content_type='image/png', return web.Response(body=buffer.read(), content_type='image/png',
headers={"Content-Disposition": f"filename=\"{filename}\""}) headers={"Content-Disposition": f"attachment; filename=\"{filename}\""})
elif channel == 'a': elif channel == 'a':
with Image.open(file) as img: with Image.open(file) as img:
@ -597,7 +597,7 @@ class PromptServer():
alpha_buffer.seek(0) alpha_buffer.seek(0)
return web.Response(body=alpha_buffer.read(), content_type='image/png', return web.Response(body=alpha_buffer.read(), content_type='image/png',
headers={"Content-Disposition": f"filename=\"{filename}\""}) headers={"Content-Disposition": f"attachment; filename=\"{filename}\""})
else: else:
# Use the content type from asset resolution if available, # Use the content type from asset resolution if available,
# otherwise guess from the filename. # otherwise guess from the filename.
@ -614,7 +614,7 @@ class PromptServer():
return web.FileResponse( return web.FileResponse(
file, file,
headers={ headers={
"Content-Disposition": f"filename=\"{filename}\"", "Content-Disposition": f"attachment; filename=\"{filename}\"",
"Content-Type": content_type "Content-Type": content_type
} }
) )