Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KTOR-7934 Apply fix for Js target #4665

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ private fun org.w3c.fetch.Headers.mapToKtor(method: HttpMethod, attributes: Attr
append(key, value)
}

dropCompressionHeaders(method, attributes)
dropCompressionHeaders(
method,
attributes,
alwaysRemove = PlatformUtils.IS_BROWSER
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@ import io.ktor.utils.io.*
import kotlinx.io.readString
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

private const val TEST_URL = "$TEST_SERVER/compression"

class ContentEncodingIntegrationTest : ClientLoader() {

// GZipEncoder is implemented only on JVM.
// GZipEncoder is implemented only on JVM; implicitly decoded for browser
@Test
fun testGzipWithContentLengthWithoutPlugin() = clientTests(only("jvm:*", "web:Js")) {
test { client ->
val response = client.get("$TEST_URL/gzip-with-content-length")
val content = if (response.headers[HttpHeaders.ContentEncoding] == "gzip") {
GZipEncoder.decode(response.bodyAsChannel()).readRemaining().readString()
} else {
response.bodyAsText()
val content = when (response.headers[HttpHeaders.ContentEncoding]) {
"gzip" -> GZipEncoder.decode(response.bodyAsChannel()).readRemaining().readString()
null -> {
// Content-Length should be removed for browser
if (PlatformUtils.IS_BROWSER) {
assertNull(response.headers[HttpHeaders.ContentLength])
}
response.bodyAsText()
}
else -> error("Unexpected content encoding: ${response.headers[HttpHeaders.ContentEncoding]}")
}

assertEquals("Hello, world", content)
Expand Down