Ktor 3.6.0 Help

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 and GET requests and returns 405 Method Not Allowed if the client tries to use the Range 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, add the ktor-server-partial-content artifact to your build script:

implementation("io.ktor:ktor-server-partial-content:$ktor_version")
implementation "io.ktor:ktor-server-partial-content:$ktor_version"
<dependency> <groupId>io.ktor</groupId> <artifactId>ktor-server-partial-content-jvm</artifactId> <version>${ktor_version}</version> </dependency>

Install PartialContent

To install the PartialContent plugin to your application, pass it to the install function in the specified module. The following examples show how to install PartialContent:

  • In an embeddedServer() function call.

  • In an explicitly defined module() extension function on the Application class.

import io.ktor.server.engine.* import io.ktor.server.netty.* import io.ktor.server.application.* import io.ktor.server.plugins.partialcontent.* fun main() { embeddedServer(Netty, port = 8080) { install(PartialContent) // ... }.start(wait = true) }
import io.ktor.server.application.* import io.ktor.server.plugins.partialcontent.* // ... fun Application.module() { install(PartialContent) // ... }

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.

24 April 2026