Skip to content

Commit

Permalink
KTOR-5510 Fix isSent when content is ReadChannelContent (#3399)
Browse files Browse the repository at this point in the history
  • Loading branch information
marychatte authored Feb 17, 2023
1 parent fb161cd commit bee452e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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?,
Expand Down

0 comments on commit bee452e

Please sign in to comment.