The web-resources library is usable for serving files over http. It does the following things for you:
- Detects and set the right Content-Type for the resource
- Partial caching via Last-Modified, If-Modified-Since and If-Unmodified-Since header
- Partial caching via ETag, If-Match, If-None-Match header
- Sets Content-Disposition header
- Head request without content
- Optional GZIP compression
- Optional handling Expires header
- Optional handling Cache-Control header
Add the latest stable version of to the dependency management tool of your choice.
E.g. for maven:
<dependency>
<groupId>com.github.sdorra</groupId>
<artifactId>web-resources</artifactId>
<version>x.y.z</version>
</dependency>
Use the latest version from maven central:
Path path = Paths.get("myfile.txt");
WebResourceSender.create()
.withGZIP()
.withExpires(7, TimeUnit.DAYS)
.resource(path)
.send(request, response);
This project is licensed under the MIT License - see the LICENSE file for details