Бежан Александр
08/26/2018, 9:03 AM@PostMapping(value = ["success", "pending"])
fun successOrPending(request: WebRequest): String {
}
Бежан Александр
08/26/2018, 9:04 AMpost(listOf("success", "pending")) {
}
enleur
08/26/2018, 10:45 AMfun Route.myHandler(): Unit = TODO()
route("/success", Post, Route::myHandler)
route("/pending", Post, Route::myHandler)
or write interceptor for complex routingБежан Александр
08/26/2018, 10:48 AMunopinionated
, it shouldn’t force user to extract handler into a separate function.Бежан Александр
08/26/2018, 10:55 AMsuspend fun PipelineContext<Unit, ApplicationCall>.successOrPending() {
}
post("success") { successOrPending() }
post("pending") { successOrPending() }
enleur
08/26/2018, 10:56 AMБежан Александр
08/26/2018, 10:58 AMfun <http://Route.post|Route.post>(paths: List<String>, body: PipelineInterceptor<Unit, ApplicationCall>) {
paths.forEach { path ->
<http://this.post|this.post>(path, body)
}
}
post(listOf("success", "pending")) {
}
Бежан Александр
08/26/2018, 12:23 PMБежан Александр
08/26/2018, 12:24 PMБежан Александр
08/26/2018, 12:24 PMorangy
Бежан Александр
08/26/2018, 12:26 PMorangy
orangy
SessionTransport
or SessionTracker
to make it possible, if anyБежан Александр
08/26/2018, 12:31 PMorangy
cookie<TestUserSession>(cookieName, sessionStorage) {
cookie.duration = Duration.ofSeconds(0)
}
orangy
Бежан Александр
08/26/2018, 12:38 PMБежан Александр
08/26/2018, 12:40 PMorangy
Бежан Александр
08/26/2018, 12:43 PMБежан Александр
08/26/2018, 12:46 PMfun Application.sessionModule() {
install(Sessions) {
cookie<SimpleSession>(
"JSESSION_ID",
directorySessionStorage(File("../../.sessions"))) {
cookie.path = "/"
}
cookie<FlashSession>(
"FLASH_SESSION_ID") {
cookie.path = "/"
}
}
}
orangy
orangy
cookie
call install SessionTrackerByValue
, which will serialize FlashSession
and put the result in a cookieБежан Александр
08/26/2018, 1:02 PMSessionStorageMemory()
Бежан Александр
08/26/2018, 1:03 PMFlashSession
and move it to request parameters.orangy
class FlashSessionTransport(private val transport: SessionTransport) : SessionTransport {
companion object {
private val flashSessionKey = AttributeKey<Boolean>("FlashSessionReceived")
}
override fun receive(call: ApplicationCall): String? = transport.receive(call)?.also {
call.attributes.put(flashSessionKey, true)
}
override fun send(call: ApplicationCall, value: String) = if (call.attributes.getOrNull(flashSessionKey) == true)
transport.clear(call)
else
transport.send(call, value)
override fun clear(call: ApplicationCall) = transport.clear(call)
}
inline fun <S : Any> Sessions.Configuration.flash(name: String, sessionType: KClass<S>, block: CookieSessionBuilder<S>.() -> Unit) {
val builder = CookieSessionBuilder(sessionType).apply(block)
val transport = FlashSessionTransport(SessionTransportCookie(name, builder.cookie, builder.transformers))
val tracker = SessionTrackerByValue(sessionType, builder.serializer)
val provider = SessionProvider(name, sessionType, transport, tracker)
register(provider)
}
orangy
flash
instead of cookie
builder functionorangy
orangy
name
to FlashSessionTransport
and then tweak storing attributes so that you can track each name separately.