https://kotlinlang.org logo
#ktor
Title
# ktor
c

Clyde

02/07/2020, 1:14 AM
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

rocketraman

02/07/2020, 6:31 PM
I've seen this before as well, in responses other than redirects. Never figured out why it happens.
c

Clyde

02/08/2020, 9:30 AM
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.
39 Views