Skip to content
Server Plugin

AutoHeadResponse

필수 의존성: io.ktor:ktor-server-auto-head-response

코드 예시: autohead

네이티브 서버
Ktor는 Kotlin/Native를 지원하며 추가 런타임이나 가상 머신 없이 서버를 실행할 수 있습니다.
지원: ✅

AutoHeadResponse 플러그인은 GET이 정의된 모든 라우트에 대해 HEAD 요청에 자동으로 응답하는 기능을 제공합니다. AutoHeadResponse을(를) 사용하여 실제 콘텐츠를 가져오기 전에 클라이언트에서 응답을 어떤 식으로든 처리해야 하는 경우 별도의 head 핸들러를 생성하는 것을 피할 수 있습니다. 예를 들어, respondFile 함수를 호출하면 Content-LengthContent-Type 헤더가 응답에 자동으로 추가되며, 파일을 다운로드하기 전에 클라이언트에서 이 정보를 얻을 수 있습니다.

종속성 추가

AutoHeadResponse을(를) 사용하려면 빌드 스크립트에 ktor-server-auto-head-response 아티팩트를 포함해야 합니다:

Kotlin
Groovy
XML

사용법

이 기능을 활용하려면 애플리케이션에 AutoHeadResponse 플러그인을 설치해야 합니다.

kotlin
import io.ktor.server.application.*
import io.ktor.server.plugins.autohead.*
import io.ktor.server.response.*
import io.ktor.server.routing.*

fun Application.main() {
    install(AutoHeadResponse)
    routing {
        get("/home") {
            call.respondText("This is a response to a GET, but HEAD also works")
        }
    }
}

이 경우 /home 라우트는 이 동사(verb)에 대한 명시적인 정의가 없어도 HEAD 요청에 응답할 것입니다.

이 플러그인을 사용하는 경우, 동일한 GET 라우트에 대한 사용자 지정 HEAD 정의는 무시된다는 점에 유의하는 것이 중요합니다.

옵션

AutoHeadResponse은(는) 추가 구성 옵션을 제공하지 않습니다.