Describe your question
ctx.resultString method return empty string, when I want to get result at requestLogger.
so, I'm using it like below
app.after { ctx ->
ctx.attribute("resultString", ctx.resultString())
}
app.requestLogger { ctx, timeMs ->
println("ctx.attribute: ${ctx.attribute<String>("resultString")}")
}
Is this ok?
Why can't take resultString at requestLogger?
@paz-raon In Javalin when you call ctx.result(string), it's converted to an input stream internally:
fun result(resultString: String) = result(resultString.byteInputStream(responseCharset()))
When writing the response, this inputstream is consumed. You should be able to get the resultString if you call ctx.resultStream().reset() first.
@paz-raon I added a reset() to the resultString() method, so in the next version of Javalin you won't have to call reset() manually: https://github.com/tipsy/javalin/commit/f6c8d61bbff3656de90b642fb2fca1690bbd9a66.