A Clojure library for handling gross things in HTTP headers. Specifically, it can encode and parse Content-Disposition headers UTF-8 content (RFC 6266), and exposes clean APIs for working with RFC 5987 encodings generally.
user=> (use 'header-utils.content-disposition)
user=> (def s (encode "attachment" "Y͢o҉u f̴ee̡l̡ ̶fée͝bl̢e.͡.pdf"))
user=> s
"attachment;filename*=UTF-8''Y%CD%A2o%D2%89u%20f%CC%B4ee%CC%A1l%CC%A1%20%CC%B6f%C3%A9e%CD%9Dbl%CC%A2e.%CD%A1.pdf"
user=> (parse-type s)
"attachment"
user=> (parse-filename s)
"Y͢o҉u f̴ee̡l̡ ̶fée͝bl̢e.͡.pdf"
You can also specify language and additional parameters.
My goal in writing this library was the handle Content-Disposition, but I took some pains to make the proximate tools as useful as possible. Specifically:
header-utils.parameters
- encode and parse RFC 5987 parametersheader-utils.encoding
- common tools for reading/writing header valuesheader-utils.parser
- internal tool useful in extending the library (e.g. adding direct support for additional headers)
This library contains all the utilities required for adding explicit support for other headers, and actually doing so should be relatively easy. I'll add that support if/when I need them or you send me a PR.
Copyright © 2015 Zensight
Distributed under the MIT License. See LICENSE for more info.