ktor

Form Authentication in Ktor

我怕爱的太早我们不能终老 提交于 2019-12-24 03:12:54
问题 I'm new to Kotlin and Ktor trying to see the authentication part, so I got the below code. Routes "/" and "/bye" are working fine, but route "login" given blank page! package blog import kotlinx.html.* import kotlinx.html.stream.* // for createHTML import org.jetbrains.ktor.application.* import org.jetbrains.ktor.auth.* import org.jetbrains.ktor.features.* import org.jetbrains.ktor.http.* import org.jetbrains.ktor.response.* import org.jetbrains.ktor.routing.* import org.jetbrains.ktor

Handling FreeMaker template with Ktor Kotlin

别来无恙 提交于 2019-12-22 21:53:33
问题 I'm very new to Kotlin (and Java), as well as Ktor and FreeMaker , trying to make an app combining all of them, but looks I'm doing something wrong related to the FreeMaker templates manipulating. My app structure is: template.ftl : <#macro mainLayout title="Welcome"> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>${title} | Kweet</title> </head> <body> HI </body> </html> </#macro> index.ftl : <#import "template.ftl" as layout />

How to create .jar (Create Executable) of the Ktor embedded Server

倖福魔咒の 提交于 2019-12-20 00:42:34
问题 I'm very new to Kotlin and Ktor and Gradle. Was able to create embedded server as explained in Ktor site, with the following code: BlogApp.kt : package blog import org.jetbrains.ktor.netty.* import org.jetbrains.ktor.routing.* import org.jetbrains.ktor.application.* import org.jetbrains.ktor.features.* import org.jetbrains.ktor.host.* import org.jetbrains.ktor.http.* import org.jetbrains.ktor.response.* fun Application.module() { install(DefaultHeaders) install(CallLogging) install(Routing) {

Ktor Netty Server sending an empty response

时光毁灭记忆、已成空白 提交于 2019-12-13 03:52:56
问题 I'm using ktor 0.9.5. I'm trying a simple example. But when a try to connect to the server i get ERR_EMPTY_RESPONSE. This is my code. fun main(args: Array<String>) { embeddedServer(Netty, port = 8080, host = "localhost") { install(DefaultHeaders) install(CallLogging) routing { get(path = "/") { call.respondText("Hello World!!") } } }.start() } Doing some research I found that changing the project to Maven fix the problem, but because of rules of my organization I can't do it. Any other

Ktor Netty Server is returning empty response

余生颓废 提交于 2019-12-13 03:49:52
问题 The below snippet is taken from the quick start on the Ktor website. val server = embeddedServer(Netty, port = 8080) { routing { get("/") { call.respondText("Hello World!", ContentType.Text.Plain) } get("/demo") { call.respondText("HELLO WORLD!") } } server.start(wait = true) My console output looks like this [07:32:13.144 INFO ] application | No ktor.deployment.watch patterns specified, automatic reload is not active [07:32:13.308 INFO ] application | Responding at http://0.0.0.0:8080 I

How to receive JSON object in Ktor?

爷,独闯天下 提交于 2019-12-12 12:01:26
问题 I have data class defined, configured gson and created rout to handle post request as follows: data class PurchaseOrder(val buyer: String, val seller: String, val poNumber: String, val date: String, val vendorReference: String) install(ContentNegotiation) { gson { setDateFormat(DateFormat.LONG) setPrettyPrinting() } post("/purchaseOrder"){ val po = call.receive<PurchaseOrder>() println("purchase order: ${po.toString()}") call.respondText("post received", contentType = ContentType.Text.Plain)

Compiler cannot resolve classes in io.ktor.client.features.logging

夙愿已清 提交于 2019-12-11 10:53:27
问题 I'm trying to add logging for Ktor http requests in Android application. According to docs I have to add gradle dependency implementation "io.ktor:ktor-client-logging:$ktor_version" and just use this snippet val client = HttpClient() { install(Logging) { logger = Logger.DEFAULT level = LogLevel.HEADERS } } Problem is that compiler "ignores" package 'io.ktor.client.features.logging' added as a dependency. What's strange is that JsonFeature (added as similar dependency) works just fine. install

Ktor multiplatform - SSL pinning for iOS in kotlin

三世轮回 提交于 2019-12-08 12:35:23
问题 I am using below code for SSL pinning in Kotlin Multiplatform using Ktor. I am having crash at this line of code val remoteCertificateData : NSData = SecCertificateCopyData(certificate) as NSData Here is the function. override fun URLSession( session: NSURLSession, didReceiveChallenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Unit ) { val serverTrust = didReceiveChallenge.protectionSpace.serverTrust val certificate =

Ktor App's Main Method Not Called When Deployed to AppEngine

不羁岁月 提交于 2019-12-08 05:53:49
问题 Issue The Ktor application's main method is not called when deployed to AppEngine. In the applications's main method is logic to retrieve content from an API request based on a Timer and save that information to a Firestore database which a client consumes. This logic currently works when deployed in a Jar to AppEngine. However, implementing this with Ktor would save deploy time and help future proof the backend service if endpoints are required. Expected The Ktor application's main method is

Handling FreeMaker template with Ktor Kotlin

本小妞迷上赌 提交于 2019-12-06 14:12:01
I'm very new to Kotlin (and Java), as well as Ktor and FreeMaker , trying to make an app combining all of them, but looks I'm doing something wrong related to the FreeMaker templates manipulating. My app structure is: template.ftl : <#macro mainLayout title="Welcome"> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>${title} | Kweet</title> </head> <body> HI </body> </html> </#macro> index.ftl : <#import "template.ftl" as layout /> imported title: ${title} <@layout.mainLayout title="Welcome"> <div class="posts"> <h3 class="content-subhead