mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
Update UrlUtil.kt
This commit is contained in:
@@ -77,21 +77,6 @@ object UrlUtil {
|
||||
conn.instanceFollowRedirects = false
|
||||
conn.connect()
|
||||
|
||||
if (AppConfig.recordLog || BuildConfig.DEBUG) {
|
||||
val headers = conn.headerFields
|
||||
val headersString = buildString {
|
||||
headers.forEach { (key, value) ->
|
||||
value.forEach {
|
||||
append(key)
|
||||
append(": ")
|
||||
append(it)
|
||||
append("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
AppLog.put("${url.toString()} response header:\n$headersString")
|
||||
}
|
||||
|
||||
// val fileSize = conn.getContentLengthLong() / 1024
|
||||
/** Content-Disposition 存在三种情况 文件名应该用引号 有些用空格
|
||||
* filename="filename"
|
||||
@@ -113,12 +98,15 @@ object UrlUtil {
|
||||
val data = fileName.split("''")
|
||||
names.add(URLDecoder.decode(data[1], data[0]))
|
||||
} else {
|
||||
names.add(fileName)
|
||||
/* 好像不用这样
|
||||
names.add(
|
||||
String(
|
||||
fileName.toByteArray(StandardCharsets.ISO_8859_1),
|
||||
StandardCharsets.UTF_8
|
||||
)
|
||||
)
|
||||
*/
|
||||
}
|
||||
}
|
||||
names.firstOrNull()
|
||||
@@ -127,6 +115,20 @@ object UrlUtil {
|
||||
getFileNameFromPath(newUrl)
|
||||
} else {
|
||||
AppLog.put("Cannot obtain URL file name, enable recordLog for detail")
|
||||
if (AppConfig.recordLog || BuildConfig.DEBUG) {
|
||||
val headers = conn.headerFields
|
||||
val headersString = buildString {
|
||||
headers.forEach { (key, value) ->
|
||||
value.forEach {
|
||||
append(key)
|
||||
append(": ")
|
||||
append(it)
|
||||
append("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
AppLog.put("${url.toString()} response header:\n$headersString")
|
||||
}
|
||||
null
|
||||
}
|
||||
}
|
||||
@@ -156,4 +158,4 @@ object UrlUtil {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user