Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -775,12 +775,9 @@ class HomeServerRepository @Inject constructor(
private fun normalizeServerUrl(rawUrl: String): String {
val trimmed = rawUrl.trim().trimEnd('/')
if (trimmed.isBlank()) return ""
val withScheme = if (trimmed.startsWith("http://", true) || trimmed.startsWith("https://", true)) {
trimmed
} else {
"http://$trimmed"
}
return withScheme.toHttpUrlOrNull()?.toString()?.trimEnd('/').orEmpty()
// Ensure HTTPS scheme using NetworkUtils.
val secure = com.arflix.tv.util.NetworkUtils.ensureHttps(trimmed)
return secure.toHttpUrlOrNull()?.toString()?.trimEnd('/')?.orEmpty() ?: ""
}

private fun detectServerKind(productName: String, serverName: String): HomeServerKind {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,13 +753,8 @@ class IptvRepository @Inject constructor(
}
}

// Add scheme if missing.
return if (cleaned.startsWith("http://", true) || cleaned.startsWith("https://", true)) {
cleaned.removeSuffix("/")
} else {
// Default to http (most providers use http).
"http://${cleaned.removeSuffix("/")}"
}
// Use NetworkUtils to enforce HTTPS scheme.
return com.arflix.tv.util.NetworkUtils.ensureHttps(cleaned)
}

private fun buildXtreamM3uUrl(baseUrl: String, username: String, password: String): String {
Expand Down
23 changes: 23 additions & 0 deletions util/NetworkUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.arflix.tv.util

object NetworkUtils {
/**
* Returns true if the given URL uses HTTPS scheme.
*/
fun isSecureUrl(url: String): Boolean {
return url.trim().startsWith("https://", ignoreCase = true)
}

/**
* Ensures the URL has an HTTPS scheme. If the URL starts with http:// it will be replaced.
* If no scheme is present, https:// is prefixed.
*/
fun ensureHttps(url: String): String {
val trimmed = url.trim().trimEnd('/')
return when {
trimmed.startsWith("https://", ignoreCase = true) -> trimmed
trimmed.startsWith("http://", ignoreCase = true) -> trimmed.replaceFirst("http://", "https://")
else -> "https://$trimmed"
}
}
}
Loading