I'm getting `ResponseAlreadySentException`s when u...
# ktor
c
I'm getting `ResponseAlreadySentException`s when using a redirect. Stack trace:
Copy code
io.ktor.server.engine.BaseApplicationResponse$ResponseAlreadySentException: Response has already been sent
at io.ktor.server.engine.BaseApplicationResponse.commitHeaders (BaseApplicationResponse.kt:44)
at io.ktor.server.engine.BaseApplicationResponse.respondOutgoingContent$suspendImpl (BaseApplicationResponse.kt:108)
at io.ktor.server.engine.BaseApplicationResponse.respondOutgoingContent (BaseApplicationResponse.kt)
The code generating the response is:
Copy code
call.respondRedirect(signedUrl)
where
signedUrl
is a string with a URL. The redirect works - the client gets the correct result and redirects to the new path. Just wondering why there is an exception.
r
I've seen this before as well, in responses other than redirects. Never figured out why it happens.
c
Well, I figured it out. I was actually calling
respond()
on the
ApplicationCall
twice, the second time was with the return value of a function which was
Unit
. Seems that
respond(Unit)
actually sends something which was unexpected.