ComfyUI icon indicating copy to clipboard operation
ComfyUI copied to clipboard

"Content-Disposition" Header set in view_image function not matching RFC2183 rules

Open xieaoran opened this issue 1 year ago • 9 comments

Custom Node Testing

Expected Behavior

When a file is fetched from ComfyUI via the view_image function, the "Content-Disposition" response header will be set to something like filename=name.ext, which doesn't match with the definition of this specific header in RFC 2183.

This will cause certain common functions (e.g. mime.ParseMediaType in Golang) to produce an error instead of parsing out the filename successfully, thus preventing various third party downloading libraries from extracting the correct filename, leading to unexpected behavior in certain post-Comfy processing procedures.

Expected Behavior should be setting the "Content-Disposition" response header as specified in RFC 2183, which should be something like attachment; filename=name.ext.

Image Image

Actual Behavior

"Content-Disposition" response header set to something like filename=name.ext.

Steps to Reproduce

Attempt downloading a file from "/view" URL route via various third party downloading libraries (e.g. grab in Golang), resulting in saving a file named "view" locally, which normally should be correctly named like "name.ext".

Debug Logs

HTTP/1.1 200 OK
Content-Disposition: filename="vace14b_00003.mp4"
Content-Type: video/mp4
Etag: "18521d76691232cf-3102a6e"
Last-Modified: Mon, 14 Jul 2025 12:20:00 GMT
Content-Length: 51391086
Accept-Ranges: bytes
Date: Tue, 15 Jul 2025 03:51:51 GMT
connection: keep-alive

Other

No response

xieaoran avatar Jul 15 '25 03:07 xieaoran

what's the pay?

ralyodio avatar Jul 16 '25 11:07 ralyodio

Hello, I'll take this on. It seems to be a straightforward formatting issue in . I'll submit a PR with the fix shortly.

bamontejano avatar Feb 19 '26 22:02 bamontejano

Thanks for the review. The concern about transcoded responses (e.g., preview returning WEBP/JPEG when the backing file is PNG) is valid but out of scope for this PR, which specifically addresses the initial download case from issue #8914 where the file exists and the Content-Disposition header was being set to attachment; filename="" with no actual filename value.

For the transcoded preview case, a separate fix would be needed that dynamically determines the appropriate extension based on the actual content type being served. That is a different issue from what this PR resolves.

junagent avatar Mar 20 '26 18:03 junagent

Hi! I can help fix the Content-Disposition header to match RFC2183 rules. I understand the HTTP specifications and can implement the correct formatting. Please assign this to me!

jiarongmai avatar Mar 20 '26 21:03 jiarongmai

Proposal

Understanding the Issue

The view_image function in server.py sets the Content-Disposition header as filename=name.ext — missing the required attachment; disposition type prefix per RFC 2183. This breaks third-party HTTP clients that rely on strict RFC parsing (e.g. Go's mime.ParseMediaType, various download managers).

Fix Approach

In server.py, update the Content-Disposition header in view_image from:

'Content-Disposition': f'filename={filename}'

to:

'Content-Disposition': f'attachment; filename="{filename}"'

Additional hardening:

  • Wrap the filename in double quotes as required by RFC 2183 for filenames with special characters
  • URL-encode the filename for the filename* extended parameter (RFC 5987) to properly handle non-ASCII characters:
    from urllib.parse import quote
    'Content-Disposition': f"attachment; filename=\"{filename}\"; filename*=UTF-8''{quote(filename)}"
    
  • Verify preview mode (inline viewing) should use inline; instead of attachment; where appropriate

Timeline

  • Implementation: a few hours (2-3 line change + edge case handling)
  • Testing with Go mime.ParseMediaType and browser download behavior: same day
  • PR ready: within 24 hours

Ready to start immediately.

chengyixu avatar Mar 21 '26 18:03 chengyixu

Hi! I'd like to work on this bounty.

My Plan:

  • Analyze the requirements
  • Implement the solution
  • Submit PR within 24-48 hours

Payment Address:

  • Platform: OKX
  • Token: USDT (TRC20)
  • Address: YOUR_USDT_ADDRESS_HERE

Let's get this done! 🚀

zhaog100 avatar Mar 21 '26 19:03 zhaog100

Hi! I'd like to work on this bounty.

My Plan:

  • Analyze the requirements
  • Implement the solution
  • Submit PR within 24-48 hours

Payment Address:

  • Platform: OKX
  • Token: USDT (TRC20)
  • Address: YOUR_USDT_ADDRESS_HERE

Let's get this done! 🚀

zhaog100 avatar Mar 21 '26 19:03 zhaog100

/attempt

zhaog100 avatar Mar 21 '26 19:03 zhaog100

I am looking into this and will submit a PR shortly.

Jackzigen avatar Sep 10 '26 19:09 Jackzigen