合并上游更改

感谢:@821938089、@zhongerxll、@youke2580c、@Leroy-X、@Dark-Tide、@lhjgege、@3harmony、@mgz0227
This commit is contained in:
HapeLee committed 2025-09-01 00:57:17 +08:00
1 parent dccb72adab
commit 8eb4881767
87 files changed
+800 -365

No files matched your search

@@ -9,12 +9,19 @@ import io.legato.kazusa.utils.DebugLog
import io.legato.kazusa.utils.asIOException
import io.legato.kazusa.utils.splitNotBlank
import kotlinx.coroutines.delay
import okhttp3.*
import okhttp3.Call
import okhttp3.Callback
import okhttp3.EventListener
import okhttp3.Headers
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.Protocol
import okhttp3.Request
import okhttp3.Response
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.asResponseBody
import okhttp3.internal.http.HTTP_PERM_REDIRECT
import okhttp3.internal.http.HTTP_TEMP_REDIRECT
import okhttp3.internal.http.HttpMethod
import okhttp3.internal.http.StatusLine
import okio.Buffer
import okio.Source
import okio.Timeout
@@ -25,7 +32,7 @@ import org.chromium.net.UrlResponseInfo
import java.io.IOException
import java.net.ProtocolException
import java.nio.ByteBuffer
import java.util.*
import java.util.Locale
import java.util.concurrent.ArrayBlockingQueue
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
@@ -98,9 +105,15 @@ abstract class AbsCallBack(
followCount += 1
urlResponseInfoChain.add(info)
val client = okHttpClient
if (originalRequest.url.isHttps && newLocationUrl.startsWith("http://") && client.followSslRedirects) {
if (originalRequest.url.isHttps
&& newLocationUrl.startsWith("http://")
&& client.followSslRedirects
) {
followRedirect = true
} else if (!originalRequest.url.isHttps && newLocationUrl.startsWith("https://") && client.followSslRedirects) {
} else if (!originalRequest.url.isHttps
&& newLocationUrl.startsWith("https://")
&& client.followSslRedirects
) {
followRedirect = true
} else if (okHttpClient.followRedirects) {
followRedirect = true
@@ -315,7 +328,7 @@ abstract class AbsCallBack(
contentLength,
bodySource
)
}
} ?: ResponseBody.EMPTY
return Response.Builder()
.request(request)
@@ -381,9 +394,12 @@ abstract class AbsCallBack(
if (HttpMethod.permitsRequestBody(method)) {
val responseCode = userResponse.code
val maintainBody = HttpMethod.redirectsWithBody(method) ||
responseCode == StatusLine.HTTP_PERM_REDIRECT ||
responseCode == StatusLine.HTTP_TEMP_REDIRECT
if (HttpMethod.redirectsToGet(method) && responseCode != StatusLine.HTTP_PERM_REDIRECT && responseCode != StatusLine.HTTP_TEMP_REDIRECT) {
responseCode == HTTP_PERM_REDIRECT ||
responseCode == HTTP_TEMP_REDIRECT
if (HttpMethod.redirectsToGet(method)
&& responseCode != HTTP_PERM_REDIRECT
&& responseCode != HTTP_TEMP_REDIRECT
) {
requestBuilder.method("GET", null)
} else {
val requestBody = if (maintainBody) userResponse.request.body else null
@@ -16,11 +16,11 @@ import io.legato.kazusa.lib.mobi.entities.Ptagx
import io.legato.kazusa.lib.mobi.entities.TOC
import io.legato.kazusa.lib.mobi.entities.TagxHeader
import io.legato.kazusa.lib.mobi.entities.TagxTag
import io.legato.kazusa.lib.mobi.utils.and
import io.legato.kazusa.lib.mobi.utils.readString
import io.legato.kazusa.lib.mobi.utils.readUInt16Array
import io.legato.kazusa.lib.mobi.utils.readUInt32
import io.legato.kazusa.lib.mobi.utils.readUInt8
import okhttp3.internal.and
import java.io.ByteArrayInputStream
import java.io.InputStream
import java.nio.ByteBuffer
@@ -0,0 +1,7 @@
package io.legato.kazusa.lib.mobi.utils
internal infix fun Byte.and(mask: Int): Int = toInt() and mask
internal infix fun Short.and(mask: Int): Int = toInt() and mask
internal infix fun Int.and(mask: Long): Long = toLong() and mask
@@ -1,6 +1,5 @@
package io.legato.kazusa.lib.mobi.utils
import okhttp3.internal.and
import java.nio.ByteBuffer
import java.nio.charset.Charset
@@ -18,6 +18,7 @@ import io.legato.kazusa.utils.toRequestBody
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.withContext
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.asRequestBody
@@ -92,6 +93,7 @@ open class WebDav(
.replace("+", "%20")
.replace("%3A", ":")
.replace("%2F", "/")
raw.toHttpUrl().toString()
}.getOrNull()
}
private val webDavClient by lazy {
@@ -112,7 +114,14 @@ open class WebDav(
build()
}
}
val host: String? get() = url.host
private val host: String?
get() = url.host?.let {
if (it.startsWith("[")) {
it.substring(1, it.lastIndex)
} else {
it
}
}
/**
* 获取当前url文件信息
@@ -165,7 +174,7 @@ open class WebDav(
method("PROPFIND", requestBody)
}.apply {
checkResult(this)
}.body?.text()
}.body.text()
}
/**
@@ -397,8 +406,8 @@ open class WebDav(
url(url)
}.apply {
checkResult(this)
}.body?.byteStream()
return byteStream ?: throw WebDavException("WebDav下载出错\nNull Exception")
}.body.byteStream()
return byteStream
}
/**
@@ -425,7 +434,7 @@ open class WebDav(
*/
private fun checkResult(response: Response) {
if (!response.isSuccessful) {
val body = response.body?.string()
val body = response.body.string()
if (response.code == 401) {
val headers = response.headers("WWW-Authenticate")
val supportBasicAuth = headers.any {
@@ -436,7 +445,7 @@ open class WebDav(
}
}
if (response.message.isNotBlank() || body.isNullOrBlank()) {
if (response.message.isNotBlank() || body.isBlank()) {
throw WebDavException("${url}\n${response.code}:${response.message}")
}
val document = Jsoup.parse(body)