mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-16 15:01:59 +00:00
Merge pull request #961 from paregi12/master
feat: add followRedirects support to httpRequestRaw and PluginRuntime
This commit is contained in:
commit
11a1cf7ba9
4 changed files with 19 additions and 3 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -33,4 +33,5 @@ expect suspend fun httpRequestRaw(
|
|||
url: String,
|
||||
headers: Map<String, String>,
|
||||
body: String,
|
||||
followRedirects: Boolean = true,
|
||||
): RawHttpResponse
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ actual suspend fun httpRequestRaw(
|
|||
url: String,
|
||||
headers: Map<String, String>,
|
||||
body: String,
|
||||
followRedirects: Boolean,
|
||||
): RawHttpResponse =
|
||||
addonHttpClient
|
||||
.request {
|
||||
|
|
|
|||
Loading…
Reference in a new issue