hawklike
05/17/2022, 2:40 PMAfter you finish working with the HTTP client, you need to free up the resources ... callShould I call theclient.close()
close()
function in the Ktor server? And if so, where?Okan Yıldırım
05/17/2022, 5:32 PMxxfast
05/18/2022, 3:25 AMcommonMain
. Given that this ssl-disabling is slightly different for each engine, is there a way to do this neatly for each engine without having to `expect`/`actual` the whole engines for each platforms?Jonathan Lennox
05/18/2022, 5:45 PMSean Proctor
05/18/2022, 9:18 PMAmaan
05/20/2022, 1:20 AMfun Application.configureRouting() {
routing {
host("localhost:8080") {
home()
}
host("chat.localhost:8080") {
chat()
}
}
}
but that doesn't seem to work when I test it on my browser.Helio
05/20/2022, 1:24 AM1 - Converting an URL to URI usingThe snippet below works forthrows an Exceptionio.ktor.http.Url
java.net.URISyntaxException: Illegal character in query at index
Ktor 1.6.8
, but it throws the exception for Ktor 2.0.1
// The input parameters used for testing are:
// baseUrl = <http://bbc-pipelines-build-info.integration.test:8082>
// urlQueryParameters = build-info?workspace-id={5734a707-dc63-47a1-b63f-03e5d80efad5}
private fun buildBuildInfoUrl(baseUrl: String, urlQueryParameters: String) =
return Url("$baseUrl/$urlQueryParameters").toURI().toString()
The response is:
<http://bbc-pipelines-build-info.integration.test:8082/build-info?workspace-id=%7B5734a707-dc63-47a1-b63f-03e5d80efad5%7D>
Exception thrown by Ktor 2.0.1
java.net.URISyntaxException: Illegal character in query at index 78: <http://bbc-pipelines-build-info.integration.test:8082/build-info?workspace-id={5734a707-dc63-47a1-b63f-03e5d80efad5}>
at java.base/java.net.URI$Parser.fail(URI.java:2913)
at java.base/java.net.URI$Parser.checkChars(URI.java:3084)
at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3172)
at java.base/java.net.URI$Parser.parse(URI.java:3114)
at java.base/java.net.URI.<init>(URI.java:600)
at io.ktor.http.URLUtilsJvmKt.toURI(URLUtilsJvm.kt:54)
2 - Even though I’m using theLooking through the snippet below in which I define my HttpClient I would assume thatplugin with the HttpClient from my integration tests, when I set the following attributesdefaultRequest
, during the request time thehost/port/protocol
is replaced from the value I gave withhost
.localhost
host
used for the request should be bbc-pipelines-build-info.integration.test
.
fun buildClient(): HttpClient {
val buildInfoUrl = URLBuilder("<http://bbc-pipelines-build-info.integration.test:8082>").build()
return HttpClient(MockEngine) {
install(ContentNegotiation) {
json(Json {
isLenient = true
ignoreUnknownKeys = true
useArrayPolymorphism = true
})
}
defaultRequest {
url {
protocol = buildInfoUrl.protocol
port = buildInfoUrl.port
host = buildInfoUrl.host
}
header(HttpHeaderConstants.X_SLAUTH_EGRESS, true)
}
bbcPipelinesUrlHandler(buildInfoUrl)
}
}
However, when I make the request with url {encodedPath = "build-info"}
the request is done using the host as being localhost
(see snippet below). When I replace the url { encodedPath = "build-info"}
with buildInfoHttpClient.submitForm("build-info",...)
instead of localhost
, the request is sent to bbc-pipelines-build-info.integration.test
host.
suspend fun getBitbucketPipelineBuildInfo(
workspaceId: String,
): BitbucketBuildInfoResponseModel = retrying {
buildInfoHttpClient.submitForm(url {encodedPath = "build-info"}, formParameters = Parameters.build {
append(BitbucketPipelineQueryParameters.WORKSPACE_ID.field, workspaceId)
}, encodeInQuery = true).body()
}
Do you reckon you could provide an assistance for these 2 issues, please?
Thanks heaps!Slackbot
05/20/2022, 1:55 PMhafiedh
05/20/2022, 3:16 PMjmfayard
05/21/2022, 9:11 AMJan
05/21/2022, 10:41 PMdany giguere
05/23/2022, 2:59 PMJonathan Lennox
05/23/2022, 6:48 PMtestApplication
work with kotest? I'm trying to use it but my tests are hanging.Jonathan Lennox
05/23/2022, 7:52 PMTextContent
, so the test could inspect it to make sure it had the right content. With ktor 2, however, the request.body is an OutputStreamContent
- what's the best way for me to verify that its content is correct?rrva
05/24/2022, 5:56 AMbenkuly
05/24/2022, 12:38 PMscope.requestPipeline.intercept(HttpRequestPipeline.Render)
I get No request transformation found
. Without intercept
it works (json with content negotiation). Any idea why?Robert Kempton
05/24/2022, 6:22 PMSlackbot
05/24/2022, 9:38 PMRyan Brink
05/25/2022, 1:16 AMynsok
05/25/2022, 6:13 AMHttpClient {
install(Logging) {
level = <http://LogLevel.INFO|LogLevel.INFO>
}
install(HttpCache)
install(JsonFeature) {
serializer = KotlinxSerializer(json = get())
}
}
client.get {
url(url = BASE_URL)
header(HttpHeaders.CacheControl, "only-if-cached")
}
ribesg
05/25/2022, 10:32 AMJoost Klitsie
05/25/2022, 2:12 PMabstract class ApiDataSource<T>(private val httpClient: HttpClient) {
fun update(value: T) {
httpClient.put {
setBody(value) // <-- T needs to be reified
}
}
}
As of course setBody needs to have a reified type. I was looking through the functions, and nowhere can I pass a type or kclass. Am I missing something?
Also, a workaround would be to serialize the body myself (by passing the KSerializer in the constructor and Json and setBody with the serialized text), but would this be preferable? I rather serialize through using the ContentNegotiation pluginTianyu Zhu
05/25/2022, 4:15 PMHttpClient {
install(RateLimit) {
limit = 100.requestsPerSecond
}
}
Tolga ÇAĞLAYAN
05/25/2022, 4:44 PMspierce7
05/25/2022, 10:31 PMKirillov Mikhail
05/26/2022, 8:27 AMfun ApplicationCall.receiveFlow(): Flow<ByteBuffer> = flow<ByteBuffer> {
val channel = receiveChannel()
try {
while (true) {
val buffer = ByteBuffer.allocate(4096)
if (channel.readAvailable(buffer) == -1) {
break
}
buffer.flip()
emit(buffer)
}
} catch (e: Exception) {
log.error("URL: '${request.uri}' error reading body", e)
throw e
}
}
If server slowly process http request - we see increase direct byte buffers (non-heap), this buffers create netty for buffering request (buffers grows to 2 gb)
I expected back pressure in ktor, but buffers are growing...
I communicated with netty users - they recommend disable autoread at channel and use read() manually
Does ktor support back pressure? If so, how enable it?Jakub Gwóźdź
05/26/2022, 10:29 AMMuhammad Usman
05/27/2022, 1:57 PMException in thread "main" java.security.UnrecoverableKeyException: Get Key failed: Given final block not properly padded. Such issues can arise if a bad key is used during decryption.
at java.base/sun.security.pkcs12.PKCS12KeyStore.engineGetKey(PKCS12KeyStore.java:457)
at java.base/sun.security.util.KeyStoreDelegator.engineGetKey(KeyStoreDelegator.java:90)
at java.base/java.security.KeyStore.getKey(KeyStore.java:1050)
at io.ktor.server.netty.NettyChannelInitializer.<init>(NettyChannelInitializer.kt:55)
at io.ktor.server.netty.NettyApplicationEngine.createBootstrap(NettyApplicationEngine.kt:145)
at io.ktor.server.netty.NettyApplicationEngine.access$createBootstrap(NettyApplicationEngine.kt:29)
at io.ktor.server.netty.NettyApplicationEngine$bootstraps$2.invoke(NettyApplicationEngine.kt:131)
at io.ktor.server.netty.NettyApplicationEngine$bootstraps$2.invoke(NettyApplicationEngine.kt:130)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at io.ktor.server.netty.NettyApplicationEngine.getBootstraps$ktor_server_netty(NettyApplicationEngine.kt:130)
at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:177)
at org.exime.ApplicationKt.main(Application.kt:30)
at org.exime.ApplicationKt.main(Application.kt)
Caused by: javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryption.
at java.base/com.sun.crypto.provider.CipherCore.unpad(CipherCore.java:977)
at java.base/com.sun.crypto.provider.CipherCore.fillOutputBuffer(CipherCore.java:1058)
at java.base/com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:855)
at java.base/com.sun.crypto.provider.PKCS12PBECipherCore.implDoFinal(PKCS12PBECipherCore.java:408)
at java.base/com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndDESede.engineDoFinal(PKCS12PBECipherCore.java:440)
at java.base/javax.crypto.Cipher.doFinal(Cipher.java:2207)
at java.base/sun.security.pkcs12.PKCS12KeyStore.lambda$engineGetKey$0(PKCS12KeyStore.java:401)
at java.base/sun.security.pkcs12.PKCS12KeyStore$RetryWithZero.run(PKCS12KeyStore.java:291)
at java.base/sun.security.pkcs12.PKCS12KeyStore.engineGetKey(PKCS12KeyStore.java:395)
... 12 more
Process finished with exit code 1
Julius
05/27/2022, 2:53 PMrobnik
05/28/2022, 9:30 PMprocessResources
step, so if I update resources, I have to manually run the gradle task. Is this a bug in the IDE integration? https://ktor.io/docs/intellij-idea.html#run_approbnik
05/28/2022, 9:30 PMprocessResources
step, so if I update resources, I have to manually run the gradle task. Is this a bug in the IDE integration? https://ktor.io/docs/intellij-idea.html#run_appAleksei Tirman [JB]
05/30/2022, 9:17 AMrobnik
05/30/2022, 5:00 PMAleksei Tirman [JB]
05/30/2022, 5:28 PMrobnik
05/30/2022, 7:28 PMAleksei Tirman [JB]
06/01/2022, 9:07 AM