Skip to content

Conversation

@RUiNtheExtinct
Copy link

Summary

Fixes the Content-Disposition header in the /view endpoint to comply with RFC 2183 and RFC 5987.

Before: Content-Disposition: filename="name.ext"
After: Content-Disposition: attachment; filename="name.ext"; filename*=UTF-8''name.ext

Problem

The current header format is missing the required disposition-type (attachment;) per RFC 2183. This causes third-party download libraries (e.g., Go's mime.ParseMediaType) to fail to parse the filename, resulting in files being saved with incorrect names like "view" instead of the actual filename.

Reported in #8914.

Changes

  • Add create_content_disposition_header() helper function that generates RFC-compliant headers
  • Update all 4 Content-Disposition headers in the view_image endpoint
  • Provide ASCII fallback filename= for legacy clients (non-ASCII chars replaced with ?)
  • Add RFC 5987 filename*=UTF-8'' parameter for proper international filename support

Testing

  • Added unit tests covering ASCII, Unicode (Chinese, Japanese), special characters, spaces, and edge cases
  • All 9 new tests pass
  • Manual testing can be done with: curl -I "http://localhost:8188/view?filename=test.png"

Compatibility

This change is backward compatible:

  • Modern browsers/clients will use the filename* parameter for UTF-8 support
  • Legacy clients will fall back to the ASCII filename parameter
  • The attachment; disposition-type is universally supported

Fixes #8914

…oint

The Content-Disposition header was missing the required disposition-type
(attachment;) and proper encoding for non-ASCII filenames.

Changes:
- Add `create_content_disposition_header()` helper function
- Update all 4 Content-Disposition headers in view_image endpoint
- Provide ASCII fallback filename for legacy clients
- Add RFC 5987 UTF-8 encoded filename* parameter for international support

This fixes third-party download libraries (e.g., Go's mime.ParseMediaType)
failing to parse the filename correctly.

Fixes #8914
Quotes in filenames would cause malformed Content-Disposition headers:
  filename="file"name.png"  ← Invalid header with unbalanced quotes

Now quotes are replaced with single quotes in the ASCII fallback while
the UTF-8 filename* uses proper percent-encoding (%22).
Previous approach replaced " with ' which corrupts the actual filename.
RFC 2183 specifies that within a quoted-string, backslash is the escape
character. Now properly escapes both \ and " with backslash prefix.

The UTF-8 filename* parameter uses percent-encoding which correctly
preserves the original filename for modern clients.
@isaac-mcfadyen
Copy link

I believe this is a duplicate of #11377?

@RUiNtheExtinct
Copy link
Author

I see, closing it then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants