From 99ce4735c1a7fdd42de24a2c8f548d8857725069 Mon Sep 17 00:00:00 2001 From: dmitrievanthony Date: Wed, 29 Apr 2020 15:53:43 +0300 Subject: [PATCH] Fix auto head response feature (#1835). --- ktor-http/common/src/io/ktor/http/HttpMethod.kt | 16 +++++++++++++++- .../jvm/src/io/ktor/features/AutoHeadResponse.kt | 5 ++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ktor-http/common/src/io/ktor/http/HttpMethod.kt b/ktor-http/common/src/io/ktor/http/HttpMethod.kt index 8554bcc9a9a..6f9de2bb33a 100644 --- a/ktor-http/common/src/io/ktor/http/HttpMethod.kt +++ b/ktor-http/common/src/io/ktor/http/HttpMethod.kt @@ -4,11 +4,25 @@ package io.ktor.http +import io.ktor.util.* + /** * Represents an HTTP method (verb) * @property value contains method name */ -data class HttpMethod(val value: String) { +data class HttpMethod(val value: String, @InternalAPI val aggregate: List = listOf()) { + /** + * Checks if the specified HTTP [method] matches this instance of the HTTP method. Specified method matches if it's + * equal to this HTTP method or at least one of methods this HTTP method aggregates. + */ + fun match(method: HttpMethod): Boolean { + if (this == method) { + return true + } + + return aggregate.contains(method) || method.aggregate.contains(this) + } + @Suppress("KDocMissingDocumentation", "PublicApiImplicitType") companion object { val Get = HttpMethod("GET") diff --git a/ktor-server/ktor-server-core/jvm/src/io/ktor/features/AutoHeadResponse.kt b/ktor-server/ktor-server-core/jvm/src/io/ktor/features/AutoHeadResponse.kt index a69f393dcbd..d8da2c9d6d8 100644 --- a/ktor-server/ktor-server-core/jvm/src/io/ktor/features/AutoHeadResponse.kt +++ b/ktor-server/ktor-server-core/jvm/src/io/ktor/features/AutoHeadResponse.kt @@ -33,7 +33,10 @@ object AutoHeadResponse : ApplicationFeature