Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Replace raw Content-Disposition header creation with util #1075

Closed
hairmare opened this issue Apr 29, 2024 · 0 comments · Fixed by #1077
Closed

Replace raw Content-Disposition header creation with util #1075

hairmare opened this issue Apr 29, 2024 · 0 comments · Fixed by #1077
Labels

Comments

@hairmare
Copy link
Contributor

hairmare commented Apr 29, 2024

In Django 4.2 there is django.utils.http.content_disposition_header() which can help us ensure that the headers are RFC 6266 compliant.

Previous Code

response["Content-Disposition"] = f"attachment; filename={name}"

New Code

from django.utils.http import content_disposition_header

response["Content-Disposition"] = content_disposition_header(as_attachment=True, filename=name)

I'm not sure if this is the canonical way to call it, but it does add unicode support to the filename and hides some implementation specifics.

I'm not sure if its worth it, so feel free to close this if you don't think it is.

Originally posted by @hairmare in #1072 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant