Skip to content

Commit

Permalink
KTOR-7934 Apply fix for Js target
Browse files Browse the repository at this point in the history
  • Loading branch information
bjhham committed Feb 14, 2025
1 parent bd652e4 commit 315c1c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
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

0 comments on commit 315c1c1

Please sign in to comment.