Range Support
Partial responses allow clients to fetch a specified portion of a requested resource which can be helpful for download managers to pause and resume downloads. As this functionality is not needed by every web application, range support is disabled by default.
To enable this feature on server level, you may pass an additional flag to the default configuration.
val app = Layout.create()
Host.create()
.handler(app)
.defaults(rangeSupport = true)
.run()Please note that the implementation does not support multiple ranges
to be requested (which would then result in a multipart response).
Ranges are served for GET and HEAD requests answered with 200 OK and content of
a known length: such responses announce Accept-Ranges: bytes, a requested range is answered with
206 Partial Content, and a range outside of the content with 416 Range Not Satisfiable.
Scope
As the range support is implemented as a concern, you may add this functionality to any handler as needed.
val files = ResourceTree.fromDirectory("/var/www/downloads")
val layout = Layout.create()
.add("downloads", Assets.from(files).addRangeSupport())