Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/honoluluhenk/http-content-disposition
Java library for building the HTTP Content-Disposition conforming to RFC6266, RFC5987 (opinionated but correct)
https://github.com/honoluluhenk/http-content-disposition
content-disposition http rfc-6266
Last synced: about 1 month ago
JSON representation
Java library for building the HTTP Content-Disposition conforming to RFC6266, RFC5987 (opinionated but correct)
- Host: GitHub
- URL: https://github.com/honoluluhenk/http-content-disposition
- Owner: HonoluluHenk
- License: lgpl-3.0
- Created: 2020-07-02T19:13:08.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-06T21:16:46.000Z (9 months ago)
- Last Synced: 2024-10-03T09:38:02.838Z (4 months ago)
- Topics: content-disposition, http, rfc-6266
- Language: Java
- Homepage:
- Size: 182 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# http-content-disposition
Implements generating a HTTP `Content-Disposition` header conforming to [RFC 6266](https://tools.ietf.org/html/rfc6266) for the Java language.
Other Java libraries do not adhere to the RFC 6266 standard
([JavaMail MimeUtility#encodeWord](https://javaee.github.io/javamail/docs/api/javax/mail/internet/MimeUtility.html) looks fine on first glance but breaks for more esoteric UTF characters)
or come with huge dependency baggage
([Spring ContentDisposition](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/ContentDisposition.html) comes to mind).# Background
The Content-Disposition header was originally specified to only support a subset of characters of the [ISO-8859-1 character set](https://de.wikipedia.org/wiki/ISO_8859-1).
Since most systems support more characters, RFC 6266 came into life to adapt some existing [old RFC used by emails](https://tools.ietf.org/html/rfc2183) to the world of HTTP and UTF-8.
# Deviance from the RFC
A minor difference is: the RFC requires
* either the old ISO-8859-1 attribute
* or the encoded extended attribute.
This library provides both for a much improved compatibility with broken/old clients.
# Maven/Gradle dependency
This library is released as a maven artifact on [jitpack.io](https://jitpack.io).```xml
jitpack.io
jitpack.io-releases
https://jitpack.io
```
```xml
com.github.HonoluluHenk
http-content-disposition
see-github-releases```
Available versions: see [Github releases](https://github.com/HonoluluHenk/http-content-disposition/releases).
# Usage
## Basic usage
```java
void addHeader(HttpServletResponse response) {
HttpContentDisposition header = HttpContentDisposition.builder()
//.disposition(Disposition.INLINE)
.disposition(Disposition.ATTACHMENT)
.filename("I ❤ special characters")
.build();response.addHeader(header.headerName(), header.headerValue());
}
```This will generate the HTTP header:
`Content-Disposition: attachment; filename="I ? special characters"; filename*=UTF-8''I%20%E2%9D%A4%20special%20characters`
The ISO-8859-1 filename is automatically generated by doing simple Charset conversion
## Customizations
### Conversion to ISO-8859-1
In case you do not want the default character set conversion or want to supply a completely different text, you may supply your implementation of `IsoFallback` to HttpContentDisposition/the builder.
You may pass a string to the existing `OverrideIsoFallback` to override the ISO filename completely.
```java
HttpContentDisposition header = HttpContentDisposition.builder()
.disposition(Disposition.ATTACHMENT)
.filename("I ❤ special characters")
.isoFallback(new OverrideIsoFallback("I (heart) special characters"))
// convenience:
//.isoFallbackValue("I (heart) special characters")
.build();```
# License
GNU Lesser General Public License 3.0 ([LGPL-3.0](http://www.gnu.org/licenses/lgpl-3.0.html)) or later.
See also: [LICENSE.txt](LICENSE.txt)