suspend fun toHttp()

in dsl/ktor/ktor-lang/src/main/kotlin/io/kotless/dsl/ktor/app/KotlessResponse.kt [61:77]


    suspend fun toHttp(): HttpResponse {
        val content = reader.await().readBytes()

        val isBinary = headers["Content-Type"]?.let {
            val type = ContentType.parse(it)
            MimeType.forDeclaration(type.contentType, type.contentSubtype)
        }?.isBinary ?: false

        val status = status()?.value ?: 500
        val myHeaders = headers.allValues().entries().map { it.key to it.value.single() }.toMap().let { HashMap(it) }

        return if (isBinary) {
            HttpResponse(status, myHeaders, content)
        } else {
            HttpResponse(status, myHeaders, content.toString(Charsets.UTF_8))
        }
    }