From bee452e06792b813220b1b1584d458092881b03d Mon Sep 17 00:00:00 2001 From: Mariia Skripchenko <61115099+marychatte@users.noreply.github.com> Date: Fri, 17 Feb 2023 11:55:18 +0100 Subject: [PATCH] KTOR-5510 Fix isSent when content is ReadChannelContent (#3399) --- .../server/engine/BaseApplicationResponse.kt | 4 ++-- .../io/ktor/server/plugins/CompressionTest.kt | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ktor-server/ktor-server-host-common/jvmAndNix/src/io/ktor/server/engine/BaseApplicationResponse.kt b/ktor-server/ktor-server-host-common/jvmAndNix/src/io/ktor/server/engine/BaseApplicationResponse.kt index 79966f8faee..48da0ab81bf 100644 --- a/ktor-server/ktor-server-host-common/jvmAndNix/src/io/ktor/server/engine/BaseApplicationResponse.kt +++ b/ktor-server/ktor-server-host-common/jvmAndNix/src/io/ktor/server/engine/BaseApplicationResponse.kt @@ -1,6 +1,6 @@ // ktlint-disable filename /* - * Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2023 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.server.engine @@ -139,7 +139,7 @@ public abstract class BaseApplicationResponse( try { // If channel is fine, commit headers and pipe data commitHeaders(content) - return respondFromChannel(readChannel) + respondFromChannel(readChannel) } finally { readChannel.cancel() } diff --git a/ktor-server/ktor-server-tests/jvm/test/io/ktor/server/plugins/CompressionTest.kt b/ktor-server/ktor-server-tests/jvm/test/io/ktor/server/plugins/CompressionTest.kt index 416fb2946ae..0fa3f80e150 100644 --- a/ktor-server/ktor-server-tests/jvm/test/io/ktor/server/plugins/CompressionTest.kt +++ b/ktor-server/ktor-server-tests/jvm/test/io/ktor/server/plugins/CompressionTest.kt @@ -4,6 +4,8 @@ package io.ktor.server.plugins +import io.ktor.client.request.* +import io.ktor.client.statement.* import io.ktor.http.* import io.ktor.http.content.* import io.ktor.server.application.* @@ -652,6 +654,23 @@ class CompressionTest { handleAndAssert("/2", "*", null, textToCompress) } + @Test + fun testResponseShouldBeSentAfterCompression(): Unit = testApplication { + install(Compression) + routing { + get("/isSent") { + call.respond(textToCompress) + assertTrue(call.response.isSent) + } + } + + client.get("/isSent") { + headers { + append(HttpHeaders.AcceptEncoding, "gzip") + } + } + } + private fun TestApplicationEngine.handleAndAssert( url: String, acceptHeader: String?,