From 79a4f08f36422a7e17876ca19bf805146c3d7371 Mon Sep 17 00:00:00 2001 From: paregi12 Date: Wed, 6 May 2026 20:11:29 +0530 Subject: [PATCH] feat: add followRedirects support to httpRequestRaw and PluginRuntime --- .../app/features/addons/AddonPlatform.android.kt | 12 +++++++++++- .../com/nuvio/app/features/addons/AddonPlatform.kt | 1 + .../com/nuvio/app/features/plugins/PluginRuntime.kt | 8 ++++++-- .../nuvio/app/features/addons/AddonPlatform.ios.kt | 1 + 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/com/nuvio/app/features/addons/AddonPlatform.android.kt b/composeApp/src/androidMain/kotlin/com/nuvio/app/features/addons/AddonPlatform.android.kt index 2c99ed0f..e7fbe541 100644 --- a/composeApp/src/androidMain/kotlin/com/nuvio/app/features/addons/AddonPlatform.android.kt +++ b/composeApp/src/androidMain/kotlin/com/nuvio/app/features/addons/AddonPlatform.android.kt @@ -210,6 +210,7 @@ actual suspend fun httpRequestRaw( url: String, headers: Map, body: String, + followRedirects: Boolean, ): RawHttpResponse = withContext(Dispatchers.IO) { val normalizedMethod = method.uppercase() @@ -228,7 +229,16 @@ actual suspend fun httpRequestRaw( builder.method(normalizedMethod, null) }.build() - addonHttpClient.newCall(request).execute().use { response -> + val client = if (followRedirects) { + addonHttpClient + } else { + addonHttpClient.newBuilder() + .followRedirects(false) + .followSslRedirects(false) + .build() + } + + client.newCall(request).execute().use { response -> RawHttpResponse( status = response.code, statusText = response.message, diff --git a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/addons/AddonPlatform.kt b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/addons/AddonPlatform.kt index 90ddf249..36e15e6b 100644 --- a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/addons/AddonPlatform.kt +++ b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/addons/AddonPlatform.kt @@ -33,4 +33,5 @@ expect suspend fun httpRequestRaw( url: String, headers: Map, body: String, + followRedirects: Boolean = true, ): RawHttpResponse diff --git a/composeApp/src/fullCommonMain/kotlin/com/nuvio/app/features/plugins/PluginRuntime.kt b/composeApp/src/fullCommonMain/kotlin/com/nuvio/app/features/plugins/PluginRuntime.kt index 641d56ba..8d792b5e 100644 --- a/composeApp/src/fullCommonMain/kotlin/com/nuvio/app/features/plugins/PluginRuntime.kt +++ b/composeApp/src/fullCommonMain/kotlin/com/nuvio/app/features/plugins/PluginRuntime.kt @@ -103,8 +103,9 @@ internal object PluginRuntime { val method = args.getOrNull(1)?.toString() ?: "GET" val headersJson = args.getOrNull(2)?.toString() ?: "{}" val body = args.getOrNull(3)?.toString() ?: "" + val followRedirects = args.getOrNull(4) as? Boolean ?: true try { - performNativeFetch(url, method, headersJson, body) + performNativeFetch(url, method, headersJson, body, followRedirects) } catch (t: Throwable) { log.e(t) { "Fetch bridge error for $method $url" } JsonObject( @@ -315,6 +316,7 @@ internal object PluginRuntime { method: String, headersJson: String, body: String, + followRedirects: Boolean, ): String { return try { val headers = parseHeaders(headersJson).toMutableMap() @@ -328,6 +330,7 @@ internal object PluginRuntime { url = url, headers = headers, body = body, + followRedirects = followRedirects, ) } @@ -490,7 +493,8 @@ internal object PluginRuntime { var method = (options.method || 'GET').toUpperCase(); var headers = options.headers || {}; var body = options.body || ''; - var result = __native_fetch(url, method, JSON.stringify(headers), body); + var followRedirects = options.redirect !== 'manual'; + var result = __native_fetch(url, method, JSON.stringify(headers), body, followRedirects); var parsed = JSON.parse(result); return { ok: parsed.ok, diff --git a/composeApp/src/iosMain/kotlin/com/nuvio/app/features/addons/AddonPlatform.ios.kt b/composeApp/src/iosMain/kotlin/com/nuvio/app/features/addons/AddonPlatform.ios.kt index 1d628939..84943920 100644 --- a/composeApp/src/iosMain/kotlin/com/nuvio/app/features/addons/AddonPlatform.ios.kt +++ b/composeApp/src/iosMain/kotlin/com/nuvio/app/features/addons/AddonPlatform.ios.kt @@ -132,6 +132,7 @@ actual suspend fun httpRequestRaw( url: String, headers: Map, body: String, + followRedirects: Boolean, ): RawHttpResponse = addonHttpClient .request {