com.hexagonkt.http.model.HttpStatus.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http Show documentation
Show all versions of http Show documentation
HTTP classes. These classes are shared among the HTTP client and the HTTP server.
The newest version!
package com.hexagonkt.http.model
import com.hexagonkt.core.assertEnabled
import com.hexagonkt.http.model.HttpStatusType.*
import kotlin.IllegalArgumentException
data class HttpStatus(
val code: Int,
val type: HttpStatusType = when (code) {
in 100..199 -> INFORMATION
in 200..299 -> SUCCESS
in 300..399 -> REDIRECTION
in 400..499 -> CLIENT_ERROR
in 500..599 -> SERVER_ERROR
else -> throw IllegalArgumentException(INVALID_CODE_ERROR_MESSAGE + code)
}
) {
companion object {
internal const val INVALID_CODE_ERROR_MESSAGE: String =
"Error code is not in any HTTP status range (100..599): "
val codes: Map by lazy {
HTTP_STATUSES.associateBy { it.code }
}
operator fun get(code: Int): HttpStatus? =
codes[code]
}
init {
if (assertEnabled)
require(code in 100..599) { INVALID_CODE_ERROR_MESSAGE + code }
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy