Patrik Åkerfeldt
09/30/2020, 9:46 AMmbonnin
09/30/2020, 2:34 PMMake sure that you use the single-threaded version ofThat seems outdated since Ktor 1.4.1 pullsas a dependency for Ktor. Ktor for macOS and iOS requires this version.kotlinx.coroutines
-native-mt-2
? Can this be changed/should an issue be filed somewhere?atsushi-koshikizawa
09/30/2020, 4:50 PMJúlio Santos
09/30/2020, 6:03 PMEmployee.select { Employee.id = id and (Employee.name = name)}
is that correct?Reprator
09/30/2020, 7:18 PMpackage com.firstapp.auth
import com.auth0.jwt.JWT
import com.auth0.jwt.JWTVerifier
import com.auth0.jwt.algorithms.Algorithm
import io.ktor.auth.Principal
import java.util.*
object JwtConfig {
private const val secret = "my-secret" // use your own secret
private const val issuer = "com.imran" // use your own issuer
//private const val validityInMs = 10 // 1 day
private const val validityInMs = 36_000_00 * 24 // 1 day
private val algorithm = Algorithm.HMAC512(secret)
val verifier: JWTVerifier = JWT
.require(algorithm)
.withIssuer(issuer)
.build()
/**
* Produce a token for this combination of name and password
*/
fun generateToken(JWTUser: JWTUser): String = JWT.create()
.withSubject("Authentication")
.withIssuer(issuer)
.withClaim("name", JWTUser.name)
.withClaim("password", JWTUser.password)
.withExpiresAt(getExpiration()) // optional
.sign(algorithm)
/**
* Calculate the expiration Date based on current time + the given validity
*/
private fun getExpiration() = Date(System.currentTimeMillis() + validityInMs)
}
data class JWTUser(val name: String, val password: String, val other:String="default"): Principal
And then how to use refresh token?Alexander Finn
10/02/2020, 1:15 PMcall.recieve
or call.respond
- it actually hides the exception and only prints something like this:
INFO Application - 200 OK: GET - /api/v2/announcements, io failed
In the case of deserialization exception during call.recieve
it returns empty reponse with status 500, in the case of serialization durint call.respond
it returns empty response with status 200 (and this is even more of a problem).
Does it mean that the best practice is to always wrap both method calls with try..catch? Or any configuration option I can enable to make such issues more prominent in the logs and the ways responses are handled?hdarritchon
10/04/2020, 7:10 PMhdarritchon
10/05/2020, 7:04 AM/**
* Specifies size of the event group for running application code
*/
public var callGroupSize: Int = parallelism
I’d like to increase this value.Nikolay Kasyanov
10/05/2020, 7:25 AMhdarritchon
10/06/2020, 8:48 AMJanez Kolar
10/06/2020, 5:51 PMfun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
val demo: Demo = Demo()
val compute = newFixedThreadPoolContext(10, "compute")
@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
demo.generateflyingDemo()
GlobalScope.launch(Dispatchers.Default) {
while(isActive)
{
demo.demoMoving()
delay(1000)
}
}
install(Compression) {
gzip {
priority = 1.0
minimumSize(256)
}
deflate {
priority = 10.0
minimumSize(1024) // condition
}
}
install(CORS) {
method(HttpMethod.Options)
method(HttpMethod.Put)
method(HttpMethod.Delete)
method(HttpMethod.Patch)
method(HttpMethod.Get)
header(HttpHeaders.Authorization)
header(HttpHeaders.Origin)
header(HttpHeaders.XRequestId)
allowCredentials = true
anyHost() // @TODO: Don't do this in production if possible. Try to limit it.
}
install(WebSockets) {
pingPeriod = Duration.ofSeconds(15)
timeout = Duration.ofSeconds(15)
maxFrameSize = Long.MAX_VALUE
masking = false
}
install(Authentication) {
basic("myBasicAuth") {
realm = "Ktor Server"
validate { if (it.name == "test" && it.password == "password") UserIdPrincipal(it.name) else null }
}
}
install(ContentNegotiation) {
gson {
}
}
routing {
get("rc/activePeople") {
call.respondHandlingActivePeople()
}
get("/") {
call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain)
}
}
}
private suspend fun ApplicationCall.respondHandlingActivePeople() {
withContext(compute) {
respond(demo.activePeople(age = 15))
}
}
Tobi
10/07/2020, 1:23 PMCaused by: java.lang.NoSuchMethodError: No direct method <init>(Ljava/lang/String;Lkotlinx/serialization/internal/GeneratedSerializer;I)V in class Lkotlinx/serialization/internal/SerialClassDescImpl; or its super classes (declaration of 'kotlinx.serialization.internal.SerialClassDescImpl
The versions I am using:
kotlin = 1.3.72
org.jetbrains.kotlin.plugin.serialization = 1.3.72
io.ktor:ktor-client-okhttp = 1.3.1
io.ktor:ktor-client-serialization-jvm = 1.3.1
io.ktor:ktor-client-logging-jvm = 1.3.1
Which versions should I use for Kotlin 1.3.72
? Can't change that one for now...rudolf.hladik
10/07/2020, 2:27 PMJohn O'Reilly
10/07/2020, 5:06 PMSystem.err: [main] INFO io.netty.util.internal.PlatformDependent - Your platform does not provide complete low-level API for accessing direct buffers reliably. Unless explicitly requested, heap buffer will always be preferred to avoid potential system instability.
jorge.rego
10/08/2020, 9:21 AMKamilH
10/09/2020, 6:57 AMMockEngine
and it works on the JVM and JS targets, but fails on iOS with following message:
kotlin.Error: Ktor native HttpClient requires kotlinx.coroutines version with `native-mt` suffix (like `1.3.9-native-mt`). Consider checking the dependencies.
Where should I add those dependencies? I though I should add it in iosTest
like that:
sourceSets {
val iosTest by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9-native-mt")
}
}
}
but it doesn’t help. Adding to iosMain
also doesn’t change anythingMarc Knaup
10/09/2020, 10:24 PMOleg Yukhnevich
10/11/2020, 11:44 AMaleksey.tomin
10/12/2020, 7:53 AMkotlin.serialization
in native (ktor client + curl)?
Way from https://ktor.io/docs/serialization-converter.html
install(ContentNegotiation) { serialization() }
doesn’t work - ContentNegotiation
exists only for jvm.Marc Knaup
10/12/2020, 10:42 AMHttpClient
? HttpResponse.close()
is deprecated.
With CIO I get BindException: Can't assign requested address
under high load which is probably due to some (temporary?) resource leak.Elka
10/12/2020, 1:47 PMrequest
, I never get a result
as if some "deadlock" occurred.
val requestBuilder = HttpRequestBuilder().takeFrom(context.request)
val result: HttpResponse = context.client!!.request(requestBuilder)
Any idea?Trevor Ackerman
10/12/2020, 2:47 PMSatyam Agarwal
10/12/2020, 3:32 PMHttpRequestBuilder
block with url(completePath)
and it is encoding my query string. How can I stop encoding of query string.
For ktor http client jvm with CIOPeter Tran
10/12/2020, 9:16 PMOkHttp
.Shan
10/13/2020, 12:55 AMribesg
10/13/2020, 8:52 AMrsetkus
10/13/2020, 10:28 AMbitkid
10/13/2020, 5:05 PMembeddedServer(Netty, environment = environment).start(true)
do a curl on localhost:8080/version and it works (it returns some json) .. then i only change that line to
embeddedServer(Jetty, environment = environment).start(true)
hit the same URL and i get "curl: (52) Empty reply from server" any ideas?MrPowerGamerBR
10/14/2020, 1:56 AMzjuhasz
10/14/2020, 3:16 AM