Marko Novakovic
05/07/2021, 5:48 AMktor-client-cio
and ktor-client-android
in Android project? can I create pure Kotlin module and use just ktor-client-cio
engine? will that cause some problems and does ktor-client-android
have some advantages?Tom.K
05/07/2021, 4:32 PMMykola Gurov
05/07/2021, 5:31 PMChristoph Hock
05/07/2021, 6:50 PMimport org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins{
kotlin("jvm")
application
}
dependencies {
testImplementation(kotlin("test-junit5"))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.0")
implementation("io.ktor:ktor-server-netty:1.5.3")
implementation("io.ktor:ktor-html-builder:1.5.3")
implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2")
implementation("ch.qos.logback:logback-classic:1.2.3")
//implementation(project(":shared"))
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<Copy>().named("processResources") {
from(project(":client").tasks.named("browserDistribution"))
}
tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "1.8"
}
application {
mainClassName = "de.chris.webide.server.MainKt"
}
repositories {
mavenCentral()
}
My build.gradle.kts in the directory above:
plugins {
kotlin("multiplatform") version "1.5.0" apply false
kotlin("plugin.serialization") version "1.5.0" apply false
}
allprojects{
group = "de.chris.webide"
version = "1.0-SNAPSHOT"
repositories{
jcenter()
mavenCentral()
maven { url = uri("<https://dl.bintray.com/kotlin/kotlinx>") }
maven { url = uri("<https://dl.bintray.com/kotlin/ktor>") }
}
}
melatonina
05/08/2021, 9:51 AMclient.get<String>("<https://api.ipify.org>")
yields
java.io.IOException: Broken pipe
while
client.get("<https://ktor.io/>")
works just fine.
client.get<String>("<http://curlmyip.org/>")
causes
org.eclipse.jetty.io.EofException
I'm even impersonating curl:
val client = HttpClient(Jetty) {
CurlUserAgent()
}
mboudraa
05/11/2021, 2:15 PMeirikb
05/12/2021, 11:16 AMsitepodmatt
05/12/2021, 7:53 PMfun main() {
embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
configureRouting()
configureSecurity()
}.start(wait = false)
}
Ryan Rolnicki
05/13/2021, 2:18 AMheader()
function, but since many of the other standard headers have accessors already, it makes me wonder if it's something I shouldn't be using?Guilherme Delgado
05/13/2021, 11:28 AMAnnoymousGiraf
05/14/2021, 3:44 AMMichael
05/14/2021, 10:18 AMgaetan
05/15/2021, 10:07 AM/documentation/{version}/page1/
I want to redirect some direct links not containing the version number of the documentation to the last version of the doc.
/documentation/page1/
-> redirect to -> /documentation/1.0/page1/
However, when I install a redirect at the root of documentation, it is never called:
route("documentation") {
intercept(ApplicationCallPipeline.Features) {
<http://logger.info|logger.info>("Calling:: " + call.request.path())
}
Any ideas why the interception is never called?Yehonatan Levi
05/15/2021, 10:26 AMnordiauwu
05/15/2021, 3:55 PMrnett
05/16/2021, 11:23 PMwatchosX86
, but no 64 bit version. Seems like a bugJúlio Santos
05/17/2021, 1:09 AMpeekandpoke
05/17/2021, 6:33 AMNoClassDefFoundException
after the Hot-reload occurred.
The compilation takes about 5 secs. I now suspect that some of the class files might be read too early. Ktor is doing the reload of the classes on the next request. When this next request happens while not all class files are re-written, then the Class Loader might read inconsistent class files.
Does this make sense? Is there anything else I could look for? Does someone else have the same issue?
It is currently really annoying, since hot-reload basically does not work for us anymore. We need to restart the server after each change, which takes precious time and patience.
Thank you in advance!wakingrufus
05/17/2021, 12:05 PMClassCastException: kotlin.coroutines.intrinsics.CoroutineSingletons cannot be cast to ...
I am using suspend fun
as well as Flows, but I am not sure where to start with this. I posted in #coroutines but Roman suggested this is probably a ktor-specific problem. stacktrace in 🧵Peter Brottveit Bock
05/18/2021, 9:54 AMribesg
05/18/2021, 2:43 PMSebastian Kazenbroot-Guppy
05/18/2021, 7:08 PMHTTP/1.1 200
in the response header instead of HTTP/1.1 200 OK
, Heroku flips out and gives me this
http_error="Bad chunk" at=error code=H17 desc="Poorly formatted HTTP response" method=GET path="/scripts" host=<http://skg-zipziptv.herokuapp.com|skg-zipziptv.herokuapp.com> request_id=57732c4e-618a-4226-8a1b-5c3c2177faec fwd="92.233.196.104" dyno=web.1 connect=0ms service=212ms status=503 bytes= protocol=https
And when you look into error H17 in the Heroku docs, it says specifically that HTTP/1.1 200 OK
is required, very much including the OK
. Now this is pretty bogus behaviour from Heroku, I agree, but I don't see any way to get around this through the various Ktor APIs and libraries, is there a path to making Heroku happy? I've made a ticket to track this issue as even if it's not really on Ktor, I expect this will come up for other folks that don't know what's going on down the line.
https://youtrack.jetbrains.com/issue/KTOR-2705Sebastian Kazenbroot-Guppy
05/18/2021, 7:13 PMBorzdeG
05/19/2021, 2:20 PMNikky
05/19/2021, 5:01 PMpublic suspend fun closeSession() {
// we don't know why this magic is necessary
session?.close()
session?.close(CloseReason(CloseReason.Codes.GOING_AWAY,"Logging out"))
session?.closeReason?.await()
}
but i don't really know why.. and any other order or leaving any of them out seems to not do it properly anymore
could also be something in our spring-webflux backend.. i guessJosé González Gómez
05/20/2021, 11:16 AMHttpClient
using a different engine? Let's say I have the following in my production code:
val DEFAULT_CLIENT = HttpClient() {
install(JsonFeature) {
serializer = KotlinxSerializer(kotlinx.serialization.json.Json {
ignoreUnknownKeys = true
})
}
}
and then in my testing code I have the following:
val client = HttpClient(MockEngine) {
engine {
addHandler { request ->
respond(...)
}
}
install(JsonFeature) {
serializer = KotlinxSerializer(kotlinx.serialization.json.Json {
ignoreUnknownKeys = true
})
}
}
As you can see, the client configuration must be the same, so I can reproduce the client behaviour in the tests, and then I configure the MockEngine
to respond whatever I want...
I have found the following:
• HttpClient
has a constructor which takes an engine
and a userConfig
, but
◦ userConfig
is declared as private val
and I can't find any public getter
◦ I don't know if I can create a shareable HttpClientConfig
, as
▪︎ I don't explicitly use an engine in the production code, as this is a multiplatform project (iOS / Android) and I let Ktor to select the default engine per platform
▪︎ HttpClientConfig
has a type parameter HttpClientEngineConfig
which seems to depend on the engine
• You have a config method, which lets you build a new HttpClient
with additional configuration, but you can't switch to a different engine using this
So the only way I can think of to be able to do this is try to declare a shared HttpClientConfig<*>.() -> Unit
fun
which then I can use in both instantiations.
Anyway this seems like a common use case with a bit convoluted solution. Is there any other simpler way to do what I want to do?Aaron Todd
05/21/2021, 5:29 PMcommon
for ByteArray
but I'm sure I'm missing something (or even just
fun readAvailable(dest: ByteArray, offset: Int = 0, len: Int = dst.size): Int
where this function reads up to len
bytes of availableForRead
Nikky
05/22/2021, 3:59 PMConflicting application feature is already installed with the same key as `Default Headers`
?
this happens on the first line in my ktor application
block, definitly not duplicate registration in the code
seems like koin 3.0.2 pulls in kotlin 1.5.0 which messes up the classpath and confuses ktor
rolling that back fixed it for a while..
for some reason these settings have a impact.. especially language and api version
tasks.withType<KotlinCompile> {
kotlinOptions {
apiVersion = "1.3"
languageVersion = "1.3"
jvmTarget = "1.8" // TODO: install newer java and use JAVA 15/16
}
}
once i set it to language/api level 1.4
it triggers the error on startupGuilherme Delgado
05/22/2021, 5:11 PMHttpHeaders.Authorization
in a few requests and I would like to avoid calling
header(HttpHeaders.Authorization, "Bearer $accessToken")
for each HttpRequestBuilder
.
Thanks!Vasily Scherbakov
05/23/2021, 12:40 PMAccess to fetch at '<http://127.0.0.1:8080/api/run?userId=root&profile=test>' from origin '<http://localhost:3000>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled
As i understand, i should add origin to list of allowed origins in my backend app, i do this that way
install(CORS){
method(HttpMethod.Get)
method(<http://HttpMethod.Post|HttpMethod.Post>, )
method(HttpMethod.Delete)
anyHost()
host("localhost")
}
But this dont work.
This is headers of response from js clinet
'Origin': '<http://localhost:3000>',
'Content-Type': 'application/json',
'Accept': 'application/json',
'Access-Control-Request-Headers': 'Content-Type, Authorization'
Can anyone help me please?