Enable Automatic HEAD Responses

预计阅读时间: 1 分钟

Ktor can automatically provide responses to HEAD requests for existing routes that have the GET verb defined.

本特性在 io.ktor.features.AutoHeadResponse 类中定义,无需任何额外构件。


To enable automatic HEAD responses, install the AutoHeadResponse feature

fun Application.main() {
  // ...
  // ...

Configuration options


Under the covers

This feature automatically responds to HEAD requests by routing as if it were GET response and discarding the body. Since any FinalContent produced by the system has lazy content semantics, it does not incur in any performance costs for processing a GET request with a body.