Hi. When changing deprecated `Apache` engine to `A...
# ktor
r
Hi. When changing deprecated
Apache
engine to
Apache5
with Ktor 3.5.2 client, my requests are failing with
Content-Length mismatch: expected 5696 bytes, but received 20120 bytes
error. I see some old similar bugs (e.g. KTOR-7934) but I'm on the latest version and on the JVM. It looks like some problem with gzip but I'm sure my server is sending correctly gzipped data.
b
this was a problem in JS/WASM because the browser handles compression automatically so the content length doesn't match... it shouldn't happen in JVM clients
g
We had to use
customizeClient { disableContentCompression() }
in a jvm backend too
r
Unfortunately I can't reproduce the problem with a simple application. There must be some dependency issue.
I'll try to investigate tomorrow
🙏 1
The problem is Spring Boot BOM.
My `build.gradle.kts`:
Copy code
plugins {
    kotlin("jvm") version "2.4.10"
    id("org.springframework.boot") version "4.1.1"
}

group = "com.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    implementation("io.ktor:ktor-client-core:3.5.2")
    implementation("io.ktor:ktor-client-apache5:3.5.2")
    implementation("io.ktor:ktor-client-content-negotiation:3.5.2")
    implementation("io.ktor:ktor-serialization-kotlinx-json:3.5.2")
	implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
}

kotlin {
    jvmToolchain(25)
}
And the application that doesn't work:
Copy code
suspend fun main() {
    val httpClient = HttpClient(Apache5) {
        install(ContentNegotiation) {
            json()
        }
    }
    httpClient.get("<https://www.google.com>").bodyAsText()
}
From what I can see Ktor is using httpclient5
5.5.1
while Spring BOM is forcing
5.6.4
Still, in my opinion it's a very strange side effect.
b
that is a very strange side effect... apache must have made some significant changes between these two versions...
r
I also confirm just adding
implementation("org.apache.httpcomponents.client5:httpclient5:5.6.4")
instead of Spring BOM breaks Ktor as well.
Support for transparent content decompression and content compression with deflate, gzip, zstd (optional), and brotli (optional) codecs in the async transport.
This is from 5.6 release notes
Should I fill a Ktor issue?
b
sure, thanks 👍