Skip to content

Commit

Permalink
Fix auto head response feature (#1835).
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrievanthony committed Apr 29, 2020
1 parent a9c1c7b commit 99ce473
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 15 additions & 1 deletion ktor-http/common/src/io/ktor/http/HttpMethod.kt
Expand Up @@ -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<HttpMethod> = 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")
Expand Down
Expand Up @@ -33,7 +33,10 @@ object AutoHeadResponse : ApplicationFeature<ApplicationCallPipeline, Unit, Unit

// Pretend the request was with GET method so that all normal routes and interceptors work
// but in the end we will drop the content
call.mutableOriginConnectionPoint.method = HttpMethod.Get
call.mutableOriginConnectionPoint.method = HttpMethod(
"GET_OR_HEAD",
listOf(HttpMethod.Get, HttpMethod.Head)
)
}
}
}
Expand Down

0 comments on commit 99ce473

Please sign in to comment.