Relatedly, I was trying to set up compression with...
# ktor
c
Relatedly, I was trying to set up compression with Ktor 3.0.0-beta1 yesterday, although it looks like the connection request stalls. The client is on the JVM. I had the logging plugin enabled and didn’t see anything appear in the logs at all. If I commented out the
install(ContentEncoding)
block, then it started working again with logs being printed too. Are there any known issues or limitations with this in Ktor 3.0.0-beta1 or a way to troubleshoot?
a
Can you please file an issue with a code snippet attached If that seems like a bug to you?
c
I’m trying to track down a reproducible test case. Is compression compatible with using Kotlinx JSON serialization for requests/responses?
a
It should be compatible
c
As I try to come up with a reproducible example, I feel feel like I’m running into two separate issues. 1. With my ktor client/server, compression doesn’t seem to be used. 2. The server is making additional http requests to other services not run by me, and those are just hanging with no logs when compression is enabled. Can we explore 1 first? I’ve got control of both ends and it might identify if I have something wrong in my setup. I can see the Javascript client making this request:
Copy code
[Log] HttpClient: REQUEST: <http://0.0.0.0:8080/conversation> (browser-app-af282e831d4fb1165b6966980f65f7270e7bf93d795bb052749e15756d4f9fc3.js, line 2)
METHOD: HttpMethod(value=POST)
COMMON HEADERS
-> Accept: application/json
-> Accept-Charset: UTF-8
-> Accept-Encoding: gzip;q=1,deflate;q=0.5,identity;q=0
-> Authorization: ***
CONTENT HEADERS
-> Content-Length: 61
-> Content-Type: application/json
BODY Content-Type: application/json
BODY START
{"user_id":"f6ac371b-a042-493f-8418-a074f1f689b1","title":""}
BODY END
I can see the server making this response:
Copy code
[Log] HttpClient: RESPONSE: 201 Created (browser-app-af282e831d4fb1165b6966980f65f7270e7bf93d795bb052749e15756d4f9fc3.js, line 2)
METHOD: HttpMethod(value=POST)
FROM: <http://0.0.0.0:8080/conversation>
COMMON HEADERS
-> connection: keep-alive
-> content-type: application/json
-> transfer-encoding: Identity
-> x-ratelimit-limit: 20
-> x-ratelimit-remaining: 19
-> x-ratelimit-reset: 1707744514
BODY Content-Type: application/json
BODY START
{"id":"18b05757-0641-45e3-bc2d-3f7202fe99a1","created_at":"2024-02-12T12:28:34.044790Z","value":{"user_id":"f6ac371b-a042-493f-8418-a074f1f689b1","title":""}}
BODY END
From what I can tell, the client is not compressing the request (lack of content-encoding header) but it does say it’ll accept a compressed response. The server is not compressing the response though, using the identity encoding. The client is configured:
Copy code
install(ContentEncoding) {
    mode = ContentEncodingConfig.Mode.All
    gzip(1f)
    deflate(0.5f)
    identity(0f)
}
The server is configured with:
Copy code
install(Compression) {
        default()
        condition {
            // For client streaming to work, the response cannot be compressed
            // <https://youtrack.jetbrains.com/issue/KTOR-5977>
            request.uri != "/${QuestionStreamingPath.ROOT}"
        }
        excludeContentType(
            ContentType.Video.Any,
            ContentType.Image.JPEG,
            ContentType.Image.PNG,
            ContentType.Audio.Any,
            ContentType.MultiPart.Any,
            ContentType.Text.EventStream
        )
    }
a
Are you able to reproduce the compression problem with the client on the JVM platform? The browser environment might restrict Ktor client's capabilities.
c
Ok, let me test with the JVM and I’ll get back to you.
I did make some progress on #2 in the interim. I found an issue in my log4j2.xml file which was why I wasn’t seeing logs 🤦 .
116 Views