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

  1. fun Application.main() {
  2. install(AutoHeadResponse)
  3. routing {
  4. get("/home") {
  5. call.respondText("This is a response to a GET, but HEAD also works")
  6. }
  7. }
  8. }

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:

Auto Head Response - 图1

Gradle (Groovy)

Gradle (Kotlin)

Maven

Auto Head Response - 图2

  1. implementation "io.ktor.features.autoheadresponse:1.5.0"

Options

AutoHeadResponse does not provide any additional configuration options.