Merge pull request #961 from paregi12/master

feat: add followRedirects support to httpRequestRaw and PluginRuntime
This commit is contained in:
Muhammed Nayif Rahman 2026-05-07 18:38:05 +05:30 committed by GitHub
commit 11a1cf7ba9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 3 deletions

View file

@ -210,6 +210,7 @@ actual suspend fun httpRequestRaw(
url: String,
headers: Map<String, String>,
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,

View file

@ -33,4 +33,5 @@ expect suspend fun httpRequestRaw(
url: String,
headers: Map<String, String>,
body: String,
followRedirects: Boolean = true,
): RawHttpResponse

View file

@ -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,

View file

@ -132,6 +132,7 @@ actual suspend fun httpRequestRaw(
url: String,
headers: Map<String, String>,
body: String,
followRedirects: Boolean,
): RawHttpResponse =
addonHttpClient
.request {