Partial content
The PartialContent plugin adds support for handling HTTP range requests used to send only a portion of an HTTP message back to a client. This plugin is useful for streaming content or resuming partial downloads.
PartialContent
has the following limitations:
Works only for
HEAD
andGET
requests and returns405 Method Not Allowed
if the client tries to use theRange
header with other methods.Works only for responses that have the
Content-Length
header defined.Disables Compression when serving ranges.
Add dependencies
To use PartialContent
, you need to include the ktor-server-partial-content
artifact in the build script:
Install PartialContent
To install the PartialContent
plugin to the application, pass it to the install
function in the specified module. The code snippets below show how to install PartialContent
...
... inside the
embeddedServer
function call.... inside the explicitly defined
module
, which is an extension function of theApplication
class.
The PartialContent
plugin can also be installed to specific routes. This might be useful if you need different PartialContent
configurations for different application resources.
To learn how to use PartialContent
to serve a file using HTTP range requests, see the File section.