Greetings! I'm getting some rather weird behavoir ...
# ktor
r
Greetings! I'm getting some rather weird behavoir running Ktor with Thymeleaf template engine. Everything works fine from the IDE; templates render nicely, even with different containers (Tomcat, Netty, Jetty) But when I deploy to my actualy server running Tomcat 8.5.34, the templates don't work. I get a blank white screen after a few seconds of loading. Inspecting the console I get
net::ERR_INVALID_CHUNKED_ENCODING 200 (200)
both in Chrome and Firefox. All other endpoints not using the templates work fine (JSON, plain text) I have other apps running just fine on the same server using Thymeleaf, although the apps are made with SpringBoot. Any ideas?
c
Looks like a bug. Need to be reproduced first
Don't you see any error messages in the tomcat log?
Also, it could be caused by too old tomcat
r
@cy Hey! Thanks for taking the time to answer. I Guess I forgot to provide a bit more detail about my setup, which has proven to be important for the issue I'm facing. You see, I'm running Apache webserver in front of Tomcat, communicating via AJP, and after some more experimenting, I've established that I can actually receive the Thymeleaf content just fine when I bypass Apache. But even under those conditions, something seems wrong to me, because the header
Transfer-Encoding -> chunked
is set twice, as well as no
Content-Length
. So that's where I stand right now. I think Apache is confused about especially the double
Transfer-Encoding
headers, mainly because functional webapps written in Spring only set it once (deployed in Tomcat). Maybe Ktor and Tomcat are both setting it for some weird reason. But alas, I'm no web wizard, so I'm mostly doing trial and error 🤷
I don't see anything suspicious in the logs. In Tomcat (
catalina.out
), I see Thymeleaf locates the correct template file and renders it. In
mod_jk.log
I see how the request from Apache gets forwarded to an AJP worker and a response generated and sent back. I can see, however, where the SpringBoot app and Ktor apps differ in terms of headers. In the
mod_jk
log, the SpringBoot app only sets 2 headers in the response:
Copy code
[Wed Jul 24 20:27:34.375 2019] [44088:139791852492672] [debug] ajp_unmarshal_response::jk_ajp_common.c (739): (ajp13_worker) status = 200
[Wed Jul 24 20:27:34.375 2019] [44088:139791852492672] [debug] ajp_unmarshal_response::jk_ajp_common.c (746): Number of headers is = 2
[Wed Jul 24 20:27:34.375 2019] [44088:139791852492672] [debug] ajp_unmarshal_response::jk_ajp_common.c (802): (ajp13_worker) Header[0] [Content-Type] = [text/html;charset=UTF-8]
[Wed Jul 24 20:27:34.375 2019] [44088:139791852492672] [debug] ajp_unmarshal_response::jk_ajp_common.c (802): (ajp13_worker) Header[1] [Content-Language] = [en-US]
In contrast, Ktor has set 5 headers at this point:
Copy code
[Wed Jul 24 20:29:26.408 2019] [44632:139791852492672] [debug] ajp_unmarshal_response::jk_ajp_common.c (802): (ajp13_worker) Header[0] [Date] = [Wed, 24 Jul 2019 18:29:26 GMT]
[Wed Jul 24 20:29:26.408 2019] [44632:139791852492672] [debug] ajp_unmarshal_response::jk_ajp_common.c (802): (ajp13_worker) Header[1] [Server] = [ktor-server-core/1.2.2 ktor-server-core/1.2.2]
[Wed Jul 24 20:29:26.408 2019] [44632:139791852492672] [debug] ajp_unmarshal_response::jk_ajp_common.c (802): (ajp13_worker) Header[2] [Transfer-Encoding] = [chunked]
[Wed Jul 24 20:29:26.408 2019] [44632:139791852492672] [debug] ajp_unmarshal_response::jk_ajp_common.c (802): (ajp13_worker) Header[3] [Connection] = [keep-alive]
[Wed Jul 24 20:29:26.408 2019] [44632:139791852492672] [debug] ajp_unmarshal_response::jk_ajp_common.c (802): (ajp13_worker) Header[4] [Content-Type] = [text/html;charset=UTF-8]
Don't know what to make of it.