Today I found my notFound route to be not working, but unlike #1051 I was able to use a debugger and detected the following:
Due to a broken python client library that needs to be able to connect to my server, I count the bytes of the body in an afterAfter routine and set them as the Content-Length header. However, this doesn't work with the notFound filter, because the body of the response passed to the afterAfter routine is not populated. I tried to call response.body(...) inside the notFound method instead of returning the website's content, but that also doesn't work because the body that's being returned by spark is then being overwritten with the return value, kotlin.Unit (equivalent to Java's void).
Trying to find a workaround I wrote throw NotFoundException() into the notFound routine, hoping to trigger the exception handler that does correctly populate the afterAfter routine's body. However, spark just decided to use the default 404 page instead of calling the exception handler, which also didn't populate the body of the afterAfter routine's response.
Hence all scenarios resulted in a Content-Length: 0 header and caused the client to throw away all content of the response.
To resolve this issue, please make sure that the afterAfter routine's response always contains the current body that's supposed to be returned to the client.
Today I found my
notFound
route to be not working, but unlike #1051 I was able to use a debugger and detected the following:Due to a broken python client library that needs to be able to connect to my server, I count the bytes of the body in an
afterAfter
routine and set them as theContent-Length
header. However, this doesn't work with thenotFound
filter, because the body of the response passed to theafterAfter
routine is not populated. I tried to callresponse.body(...)
inside thenotFound
method instead of returning the website's content, but that also doesn't work because the body that's being returned by spark is then being overwritten with the return value,kotlin.Unit
(equivalent to Java'svoid
).Trying to find a workaround I wrote
throw NotFoundException()
into thenotFound
routine, hoping to trigger theexception
handler that does correctly populate theafterAfter
routine's body. However, spark just decided to use the default 404 page instead of calling theexception
handler, which also didn't populate the body of theafterAfter
routine's response.Hence all scenarios resulted in a
Content-Length: 0
header and caused the client to throw away all content of the response.To resolve this issue, please make sure that the
afterAfter
routine's response always contains the current body that's supposed to be returned to the client.