dev.pellet.server.codec.http.HTTPHeaders.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pellet-server Show documentation
Show all versions of pellet-server Show documentation
An opinionated Kotlin web framework, with best-practices built-in
package dev.pellet.server.codec.http
import java.util.Locale
data class HTTPHeaders(
private val storage: MutableMap> = mutableMapOf()
) {
fun getSingleOrNull(headerName: String): HTTPHeader? {
val headers = get(headerName)
if (headers.size != 1) {
return null
}
return headers.firstOrNull()
}
fun get(headerName: String): List {
val normalisedName = normaliseName(headerName)
return storage[normalisedName] ?: listOf()
}
fun add(header: HTTPHeader): HTTPHeaders {
val normalisedName = normaliseName(header.rawName)
val list = storage[normalisedName] ?: mutableListOf()
list.add(header)
storage[normalisedName] = list
return this
}
private fun normaliseName(headerName: String): String {
return headerName.lowercase(Locale.ENGLISH)
}
override fun toString(): String {
return storage.toString()
}
fun forEach(lambda: (String, List) -> Unit) {
storage.forEach {
lambda(it.key, it.value)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy