From 18d4bc89ac66606ed3b65b4ad4618590ad134170 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Wed, 13 Sep 2023 16:53:36 +0200 Subject: [PATCH 1/3] Fix redirects only working for GET requests. --- .../io/realm/kotlin/mongodb/internal/HttpClientCache.kt | 5 ++++- .../kotlin/io/realm/kotlin/test/mongodb/util/HttpClient.kt | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/HttpClientCache.kt b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/HttpClientCache.kt index d918aa4d6a..af58d47703 100644 --- a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/HttpClientCache.kt +++ b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/HttpClientCache.kt @@ -2,6 +2,7 @@ package io.realm.kotlin.mongodb.internal import io.ktor.client.HttpClient import io.ktor.client.HttpClientConfig +import io.ktor.client.plugins.HttpRedirect import io.ktor.client.plugins.HttpTimeout import io.ktor.client.plugins.logging.LogLevel import io.ktor.client.plugins.logging.Logger @@ -34,7 +35,9 @@ internal fun createClient(timeoutMs: Long, customLogger: Logger?): HttpClient { } } - followRedirects = true + install(HttpRedirect) { + checkHttpMethod = false + } } } diff --git a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/HttpClient.kt b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/HttpClient.kt index cc8a6ee969..da9e02c6e7 100644 --- a/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/HttpClient.kt +++ b/packages/test-sync/src/commonMain/kotlin/io/realm/kotlin/test/mongodb/util/HttpClient.kt @@ -18,6 +18,7 @@ package io.realm.kotlin.test.mongodb.util import io.ktor.client.HttpClient import io.ktor.client.HttpClientConfig +import io.ktor.client.plugins.HttpRedirect import io.ktor.client.plugins.HttpTimeout import io.ktor.client.plugins.contentnegotiation.ContentNegotiation import io.ktor.client.plugins.logging.Logger @@ -65,7 +66,11 @@ fun defaultClient(name: String, debug: Boolean, block: HttpClientConfig<*>.() -> } } - followRedirects = true + // We should allow redirects for all types, not just GET and HEAD + // See https://github.com/ktorio/ktor/issues/1793 + install(HttpRedirect) { + checkHttpMethod = false + } // TODO connectionPool? this.apply(block) From 766b32d41250f17674c9c7c6b1cf11d5b7e4b880 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Wed, 13 Sep 2023 16:55:44 +0200 Subject: [PATCH 2/3] Add missing comment --- .../kotlin/io/realm/kotlin/mongodb/internal/HttpClientCache.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/HttpClientCache.kt b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/HttpClientCache.kt index af58d47703..208769c6f9 100644 --- a/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/HttpClientCache.kt +++ b/packages/library-sync/src/commonMain/kotlin/io/realm/kotlin/mongodb/internal/HttpClientCache.kt @@ -35,6 +35,8 @@ internal fun createClient(timeoutMs: Long, customLogger: Logger?): HttpClient { } } + // We should allow redirects for all types, not just GET and HEAD + // See https://github.com/ktorio/ktor/issues/1793 install(HttpRedirect) { checkHttpMethod = false } From 8842f8c4f0d534b4b43665fb842433755e7c26d1 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Wed, 13 Sep 2023 16:59:27 +0200 Subject: [PATCH 3/3] Add changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa46f86430..f5bc4628fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ * None. ### Fixed -* None. +* [Sync] If calling a function on App Services that resulted in a redirect, it would only redirect for GET requests. (Issue [#1517](https://github.com/realm/realm-kotlin/pull/1517)) ### Compatibility * File format: Generates Realms with file format v23.