Auto Head Response
Description
The AutoHeadResponse
feature provides us with the ability to automatically respond to HEAD
request for every route that has a GET
defined.
Usage
In order to take advantage of this functionality, we need to install the AutoHeadResponse
feature in our application
fun Application.main() {
install(AutoHeadResponse)
routing {
get("/home") {
call.respondText("This is a response to a GET, but HEAD also works")
}
}
}
In our case the /home
route will now respond to HEAD
request even though there is no explicit definition for this verb.
It’s important to note that if we’re using this feature, custom HEAD
definitions for the same GET
route will be ignored.
Artifacts
The following artifacts need to be included in the build script to use this feature:
Gradle (Groovy)
Gradle (Kotlin)
Maven
implementation "io.ktor.features.autoheadresponse:1.5.0"
Options
AutoHeadResponse
does not provide any additional configuration options.