mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-17 07:21:58 +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,
|
url: String,
|
||||||
headers: Map<String, String>,
|
headers: Map<String, String>,
|
||||||
body: String,
|
body: String,
|
||||||
|
followRedirects: Boolean,
|
||||||
): RawHttpResponse =
|
): RawHttpResponse =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val normalizedMethod = method.uppercase()
|
val normalizedMethod = method.uppercase()
|
||||||
|
|
@ -228,7 +229,16 @@ actual suspend fun httpRequestRaw(
|
||||||
builder.method(normalizedMethod, null)
|
builder.method(normalizedMethod, null)
|
||||||
}.build()
|
}.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(
|
RawHttpResponse(
|
||||||
status = response.code,
|
status = response.code,
|
||||||
statusText = response.message,
|
statusText = response.message,
|
||||||
|
|
|
||||||
|
|
@ -33,4 +33,5 @@ expect suspend fun httpRequestRaw(
|
||||||
url: String,
|
url: String,
|
||||||
headers: Map<String, String>,
|
headers: Map<String, String>,
|
||||||
body: String,
|
body: String,
|
||||||
|
followRedirects: Boolean = true,
|
||||||
): RawHttpResponse
|
): RawHttpResponse
|
||||||
|
|
|
||||||
|
|
@ -103,8 +103,9 @@ internal object PluginRuntime {
|
||||||
val method = args.getOrNull(1)?.toString() ?: "GET"
|
val method = args.getOrNull(1)?.toString() ?: "GET"
|
||||||
val headersJson = args.getOrNull(2)?.toString() ?: "{}"
|
val headersJson = args.getOrNull(2)?.toString() ?: "{}"
|
||||||
val body = args.getOrNull(3)?.toString() ?: ""
|
val body = args.getOrNull(3)?.toString() ?: ""
|
||||||
|
val followRedirects = args.getOrNull(4) as? Boolean ?: true
|
||||||
try {
|
try {
|
||||||
performNativeFetch(url, method, headersJson, body)
|
performNativeFetch(url, method, headersJson, body, followRedirects)
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
log.e(t) { "Fetch bridge error for $method $url" }
|
log.e(t) { "Fetch bridge error for $method $url" }
|
||||||
JsonObject(
|
JsonObject(
|
||||||
|
|
@ -315,6 +316,7 @@ internal object PluginRuntime {
|
||||||
method: String,
|
method: String,
|
||||||
headersJson: String,
|
headersJson: String,
|
||||||
body: String,
|
body: String,
|
||||||
|
followRedirects: Boolean,
|
||||||
): String {
|
): String {
|
||||||
return try {
|
return try {
|
||||||
val headers = parseHeaders(headersJson).toMutableMap()
|
val headers = parseHeaders(headersJson).toMutableMap()
|
||||||
|
|
@ -328,6 +330,7 @@ internal object PluginRuntime {
|
||||||
url = url,
|
url = url,
|
||||||
headers = headers,
|
headers = headers,
|
||||||
body = body,
|
body = body,
|
||||||
|
followRedirects = followRedirects,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -490,7 +493,8 @@ internal object PluginRuntime {
|
||||||
var method = (options.method || 'GET').toUpperCase();
|
var method = (options.method || 'GET').toUpperCase();
|
||||||
var headers = options.headers || {};
|
var headers = options.headers || {};
|
||||||
var body = options.body || '';
|
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);
|
var parsed = JSON.parse(result);
|
||||||
return {
|
return {
|
||||||
ok: parsed.ok,
|
ok: parsed.ok,
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,7 @@ actual suspend fun httpRequestRaw(
|
||||||
url: String,
|
url: String,
|
||||||
headers: Map<String, String>,
|
headers: Map<String, String>,
|
||||||
body: String,
|
body: String,
|
||||||
|
followRedirects: Boolean,
|
||||||
): RawHttpResponse =
|
): RawHttpResponse =
|
||||||
addonHttpClient
|
addonHttpClient
|
||||||
.request {
|
.request {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue