Update UrlUtil.kt

This commit is contained in:
Xwite
2023-03-17 10:21:16 +08:00
committed by GitHub
parent 522b195072
commit 785b8f5483

View File

@@ -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 {
}
}
}
}