All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmAndNixMain.transport.ktor.HttpServer.kt Maven / Gradle / Ivy

The newest version!
package ch.softappeal.yass2.transport.ktor

import ch.softappeal.yass2.remote.Request
import ch.softappeal.yass2.remote.Tunnel
import ch.softappeal.yass2.transport.Transport
import io.ktor.server.application.ApplicationCall
import io.ktor.server.application.call
import io.ktor.server.request.receiveChannel
import io.ktor.server.response.respond
import io.ktor.server.routing.Route
import io.ktor.server.routing.post
import io.ktor.server.routing.route
import kotlinx.coroutines.withContext
import kotlin.coroutines.AbstractCoroutineContextElement
import kotlin.coroutines.CoroutineContext

public class CallCce(public val call: ApplicationCall) : AbstractCoroutineContextElement(CallCce) {
    public companion object Key : CoroutineContext.Key
}

public fun Route.route(transport: Transport, path: String, tunnel: Tunnel) {
    route(path) {
        post {
            withContext(CallCce(call)) {
                val length = call.request.headers["Content-Length"]!!.toInt()
                val reply = tunnel(call.receiveChannel().read(transport, length) as Request)
                call.respond(transport.write(reply))
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy