commonMain.io.ktor.http.cio.CIOHeaders.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ktor-http-cio-tvosarm64 Show documentation
Show all versions of ktor-http-cio-tvosarm64 Show documentation
Ktor is a framework for quickly creating web applications in Kotlin with minimal effort.
The newest version!
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
package io.ktor.http.cio
import io.ktor.http.*
import io.ktor.util.*
/**
* An adapter from CIO low-level headers map to ktor [Headers] interface
*/
public class CIOHeaders(private val headers: HttpHeadersMap) : Headers {
private val names: Set by lazy(LazyThreadSafetyMode.NONE) {
LinkedHashSet(headers.size).apply {
for (i in 0 until headers.size) {
add(headers.nameAt(i).toString())
}
}
}
override val caseInsensitiveName: Boolean get() = true
override fun names(): Set = names
override fun get(name: String): String? = headers[name]?.toString()
override fun getAll(name: String): List? =
headers.getAll(name).map { it.toString() }.toList().takeIf { it.isNotEmpty() }
override fun isEmpty(): Boolean = headers.size == 0
override fun entries(): Set>> {
return (0 until headers.size).map { idx -> Entry(idx) }.toSet()
}
private inner class Entry(private val idx: Int) : Map.Entry> {
override val key: String get() = headers.nameAt(idx).toString()
override val value: List get() = listOf(headers.valueAt(idx).toString())
}
}