-
-
Save marrek13/89fc75d0cb2323b7ca0c9b3d8a91bafd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class ApiVersionCondition(private val apiVersion: ApiVersionValue) : RequestCondition<ApiVersionCondition> { | |
override fun combine(other: ApiVersionCondition) = ApiVersionCondition(other.apiVersion) | |
override fun getMatchingCondition(request: HttpServletRequest): ApiVersionCondition? { | |
val requestApiVersion = | |
request.getHeader(ACCEPT_VERSION_HEADER) | |
?.let { ApiVersionValue.valueOf("V${it.replace('.', '_')}") } | |
?: ApiVersionValue.V1_0_0 | |
if (requestApiVersion >= apiVersion) { | |
return this | |
} | |
return null | |
} | |
override fun compareTo(other: ApiVersionCondition, request: HttpServletRequest): Int = other.apiVersion.compareTo(apiVersion) | |
companion object { | |
const val ACCEPT_VERSION_HEADER = "accept-version" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment