Luca
05/16/2024, 4:02 AMAleksei Tirman [JB]
05/16/2024, 7:14 AMFileStorage
interacts only with the file system so it works offline. Can you share the code where you test this behavior?Luca
05/16/2024, 10:08 PMkamel-samples
(which opens to the gallery page that loads remote images that are cached) once online to save the data then again offline to try and load the gallery.
It will fail to load the cached image data after calling an api offline:
jvm desktop for example will fail with:
java.nio.channels.UnresolvedAddressException
at java.base/sun.nio.ch.Net.checkAddress(Net.java:137)
at java.base/sun.nio.ch.Net.checkAddress(Net.java:145)
at java.base/sun.nio.ch.SocketChannelImpl.checkRemote(SocketChannelImpl.java:842)
at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:865)
at io.ktor.network.sockets.SocketImpl.connect$ktor_network(SocketImpl.kt:44)
at io.ktor.network.sockets.ConnectUtilsJvmKt.connect(ConnectUtilsJvm.kt:21)
at io.ktor.network.sockets.TcpSocketBuilder.connect(TcpSocketBuilder.kt:37)
at io.ktor.client.engine.cio.ConnectionFactory.connect(ConnectionFactory.kt:30)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invokeSuspend(Endpoint.kt:207)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invoke(Endpoint.kt)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invoke(Endpoint.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(Undispatched.kt:72)
at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:148)
at kotlinx.coroutines.TimeoutKt.withTimeoutOrNull(Timeout.kt:104)
at io.ktor.client.engine.cio.Endpoint.connect(Endpoint.kt:215)
at io.ktor.client.engine.cio.Endpoint.makeDedicatedRequest(Endpoint.kt:100)
at io.ktor.client.engine.cio.Endpoint.execute(Endpoint.kt:64)
at io.ktor.client.engine.cio.CIOEngine.execute(CIOEngine.kt:79)
at io.ktor.client.engine.HttpClientEngine$executeWithinCallContext$2.invokeSuspend(HttpClientEngine.kt:99)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:111)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702)
Luca
05/16/2024, 10:11 PMCacheStorage
implementation.
https://github.com/Kamel-Media/Kamel/blob/013f42e1c6bff04e99890b9bc6e8ca09601d4015[…]/commonMain/kotlin/io/kamel/core/cache/disk/DiskCacheStorage.kt
and it is installed in the client here:
https://github.com/Kamel-Media/Kamel/blob/b5bb34d86b9e65e448451b20412b5ed275ad60fa[…]rc/commonMain/kotlin/io/kamel/core/config/KamelConfigBuilder.kt
This is how requests are made:
https://github.com/Kamel-Media/Kamel/blob/013f42e1c6bff04e99890b9bc6e8ca09601d4015[…]core/src/commonMain/kotlin/io/kamel/core/fetcher/HttpFetcher.kt
CacheStorage.find
is not called at all when offlineAleksei Tirman [JB]
05/17/2024, 7:40 AMLuca
05/17/2024, 7:14 PMLuca
05/20/2024, 12:42 AMException in thread "main" java.nio.channels.UnresolvedAddressException
at java.base/sun.nio.ch.Net.checkAddress(Net.java:149)
at java.base/sun.nio.ch.Net.checkAddress(Net.java:157)
at java.base/sun.nio.ch.SocketChannelImpl.checkRemote(SocketChannelImpl.java:816)
at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:839)
at io.ktor.network.sockets.SocketImpl.connect$ktor_network(SocketImpl.kt:44)
at io.ktor.network.sockets.ConnectUtilsJvmKt.connect(ConnectUtilsJvm.kt:21)
at io.ktor.network.sockets.TcpSocketBuilder.connect(TcpSocketBuilder.kt:37)
at io.ktor.client.engine.cio.ConnectionFactory.connect(ConnectionFactory.kt:30)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invokeSuspend(Endpoint.kt:207)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invoke(Endpoint.kt)
at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invoke(Endpoint.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(Undispatched.kt:89)
at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:151)
at kotlinx.coroutines.TimeoutKt.withTimeoutOrNull(Timeout.kt:107)
at io.ktor.client.engine.cio.Endpoint.connect(Endpoint.kt:215)
at io.ktor.client.engine.cio.Endpoint.makeDedicatedRequest(Endpoint.kt:100)
at io.ktor.client.engine.cio.Endpoint.execute(Endpoint.kt:64)
at io.ktor.client.engine.cio.CIOEngine.execute(CIOEngine.kt:79)
at io.ktor.client.engine.HttpClientEngine$executeWithinCallContext$2.invokeSuspend(HttpClientEngine.kt:99)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:100)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
FAILURE: Build failed with an exception.
Aleksei Tirman [JB]
05/20/2024, 8:04 AMpicsum.photos
to the fastly.picsum.photos
, which requires a connection, too. So, if I add the following mappings into the hosts
file:
104.26.4.30 picsum.photos
146.75.117.91 fastly.picsum.photos
And replace the URLs with the ones located by the redirect:
client.get("<https://fastly.picsum.photos/id/134/500/500.jpg?hmac=B9KyHkmMllXNwIDo64ywJL9MAt8E-paC3WhMGHTfcy4>")
client.get("<https://fastly.picsum.photos/id/134/500/500.jpg?hmac=B9KyHkmMllXNwIDo64ywJL9MAt8E-paC3WhMGHTfcy4>")
Then, the second code run works without a connection to the network.Luca
05/20/2024, 3:43 PMLuca
05/20/2024, 3:47 PMAleksei Tirman [JB]
05/20/2024, 6:55 PMLuca
05/20/2024, 8:10 PMAleksei Tirman [JB]
05/21/2024, 7:49 AMSend
hook. Here is an example:
val plugin = createClientPlugin("my plugin") {
on(Send) { request ->
val call = proceed(request)
if (listOf(301, 302, 307, 308).contains(call.response.status.value)) {
println(call.response.headers[HttpHeaders.Location])
}
call
}
}