/*
 * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
 */

package io.ktor.server.http

import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.testing.*
import kotlin.test.*

class RespondFunctionsJvmTest {
    @Test
    fun testRespondBytes() = testApplication {
        routing {
            get("/output-stream") {
                call.respondOutputStream(contentLength = 2) { write(1); write(2) }
            }
            get("/text-writer") {
                call.respondTextWriter(contentLength = 2) { write(1); write(2) }
            }
        }

        client.get("/output-stream").let { response ->
            assertEquals("1, 2", response.bodyAsBytes().joinToString())
            assertEquals("2", response.headers[HttpHeaders.ContentLength])
        }
        client.get("/text-writer").let { response ->
            assertEquals("1, 2", response.bodyAsBytes().joinToString())
            assertEquals("2", response.headers[HttpHeaders.ContentLength])
        }
    }
}
