ComfyUI/test_rfc2183_fix.py
andygoodluck 491372b827 fix: Make Content-Disposition header RFC 2183 compliant
Changes all Content-Disposition headers from:
  filename="name.ext"
to:
  attachment; filename="name.ext"

This ensures compatibility with RFC 2183 and allows third-party
downloading libraries (e.g., Go's mime.ParseMediaType) to correctly
parse the filename.

Fixes #8914
2026-02-14 09:49:34 +08:00

50 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""
Test for Content-Disposition header fix
Verifies that the header matches RFC 2183 format
"""
import re
def test_content_disposition_header():
"""Test that Content-Disposition header is RFC 2183 compliant"""
# Read the server.py file
with open('server.py', 'r') as f:
content = f.read()
# Find all Content-Disposition headers
pattern = r'"Content-Disposition":\s*f"([^"]+)"'
matches = re.findall(pattern, content)
print(f"Found {len(matches)} Content-Disposition headers")
all_pass = True
for i, match in enumerate(matches, 1):
print(f"\nHeader {i}: {match}")
# Check RFC 2183 compliance
# Should start with "attachment;" or "inline;" followed by filename
if match.startswith("attachment;") and "filename=" in match:
print(f" ✅ RFC 2183 compliant (attachment disposition)")
elif match.startswith("inline;") and "filename=" in match:
print(f" ✅ RFC 2183 compliant (inline disposition)")
elif match.startswith("filename="):
print(f" ❌ NOT RFC 2183 compliant (missing disposition type)")
all_pass = False
else:
print(f" ⚠️ Unknown format")
print("\n" + "="*50)
if all_pass:
print("✅ All headers are RFC 2183 compliant!")
else:
print("❌ Some headers are NOT RFC 2183 compliant!")
return all_pass
if __name__ == "__main__":
import sys
success = test_content_disposition_header()
sys.exit(0 if success else 1)