fix: encode Unicode filenames in Content-Disposition headers#39
Merged
tofran merged 2 commits intosignifica:mainfrom May 6, 2025
Merged
fix: encode Unicode filenames in Content-Disposition headers#39tofran merged 2 commits intosignifica:mainfrom
tofran merged 2 commits intosignifica:mainfrom
Conversation
Previously, the server failed to handle APK filenames containing non-Latin characters (e.g., Chinese) due to HTTP header encoding limitations. The `latin-1` requirement for headers caused `UnicodeEncodeError` when returning filenames with Unicode characters. This change: 1. Uses `urllib.parse.quote()` to percent-encode Unicode filenames 2. Adopts RFC 5987 `filename*=` syntax with UTF-8 encoding 3. Ensures compatibility with browsers while preserving original filenames Example: - Old: `filename=测试.apk` → Broken (invalid header) - New: `filename*=UTF-8''%E6%B5%8B%E8%AF%95.apk` → Works (decodes as "测试.apk") Fixes significa#38
7eeb695 to
25da4af
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, the server failed to handle APK filenames containing non-Latin characters (e.g., Chinese) due to HTTP header encoding limitations. The
latin-1requirement for headers causedUnicodeEncodeErrorwhen returning filenames with Unicode characters.This change:
urllib.parse.quote()to percent-encode Unicode filenamesfilename*=syntax with UTF-8 encodingExample:
filename=测试.apk→ Broken (invalid header)filename*=UTF-8''%E6%B5%8B%E8%AF%95.apk→ Works (decodes as "测试.apk")Fixes #38