ContentDisposition
helps properly formatting Content-Disposition headers.
Inspired by Ruby's content_disposition
gem,
this package formats a given disposition and optional filename to an acceptable value for the
Content-Disposition
header. It takes care of encoding, escaping and adds an ASCII fallback.
# Without filename
iex> ContentDisposition.format(disposition: :inline)
"inline"
# With a filename, and disposition as a string
iex> ContentDisposition.format(disposition: "inline", filename: "kitten.jpg")
"inline; filename=\"kitten.jpg\"; filename*=UTF-8''kitten.jpg"
# With a UTF-8 filename as attachment
iex> ContentDisposition.format(disposition: :attachment, filename: "kïttéñ.jpg")
"attachment; filename=\"k%3Ftt%3F%3F.jpg\"; filename*=UTF-8''k%C3%AFtt%C3%A9%C3%B1.jpg"
Add content_disposition
to your list of dependencies in mix.exs
:
def deps do
[{:content_disposition, "~> 1.0.0"}]
end
This library is MIT licensed. See the LICENSE file in this repository for details.