Skip to content

Commit 818e693

Browse files
authored
Fix duplicate requests in WebView due to empty reasonPhrase (#2003)
1 parent ecc6ede commit 818e693

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
3838
- Fix app bar action tooltips blocking clicks ([@Bartuzen](https://github.com/Bartuzen)) ([#1928](https://github.com/mihonapp/mihon/pull/1928))
3939
- Fix unintended app permissions due to Firebase misconfiguration ([@AntsyLich](https://github.com/AntsyLich)) ([#1960](https://github.com/mihonapp/mihon/pull/1960))
4040
- Fix navigation issue after migrating a duplicated entry from History tab ([@cuong-tran](https://github.com/cuong-tran)) ([#1980](https://github.com/mihonapp/mihon/pull/1980))
41+
- Fix duplicate requests in WebView due to empty reasonPhrase ([@AwkwardPeak7](https://github.com/AwkwardPeak7)) ([#2003](https://github.com/mihonapp/mihon/pull/2003))
4142

4243
## [v0.18.0] - 2025-03-20
4344
### Added

app/src/main/java/eu/kanade/presentation/webview/WebViewScreenContent.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ import eu.kanade.tachiyomi.util.system.getHtml
4545
import eu.kanade.tachiyomi.util.system.setDefaultSettings
4646
import kotlinx.collections.immutable.persistentListOf
4747
import kotlinx.coroutines.launch
48+
import logcat.LogPriority
4849
import okhttp3.Request
50+
import tachiyomi.core.common.util.system.logcat
4951
import tachiyomi.i18n.MR
5052
import tachiyomi.presentation.core.components.material.Scaffold
5153
import tachiyomi.presentation.core.i18n.stringResource
@@ -145,16 +147,18 @@ fun WebViewScreenContent(
145147

146148
val contentType = response.body.contentType()?.let { "${it.type}/${it.subtype}" } ?: "text/html"
147149
val contentEncoding = response.body.contentType()?.charset()?.name() ?: "utf-8"
150+
val message = response.message.ifBlank { WebViewUtil.getMessageFromHttpStatusCode(response.code) }
148151

149152
WebResourceResponse(
150153
contentType,
151154
contentEncoding,
152155
response.code,
153-
response.message,
156+
message,
154157
response.headers.associate { it.first to it.second },
155158
response.body.byteStream(),
156159
)
157160
} catch (e: Throwable) {
161+
logcat(priority = LogPriority.ERROR, throwable = e)
158162
super.shouldInterceptRequest(view, request)
159163
}
160164
}

core/common/src/main/kotlin/eu/kanade/tachiyomi/util/system/WebViewUtil.kt

+69
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,75 @@ object WebViewUtil {
6464
SYSTEM_SETTINGS_PACKAGE
6565
}
6666
}
67+
68+
fun getMessageFromHttpStatusCode(code: Int): String {
69+
return when (code) {
70+
100 -> "Continue"
71+
101 -> "Switching Protocols"
72+
102 -> "Processing"
73+
103 -> "Early Hints"
74+
200 -> "OK"
75+
201 -> "Created"
76+
202 -> "Accepted"
77+
203 -> "Non-Authoritative Information"
78+
204 -> "No Content"
79+
205 -> "Reset Content"
80+
206 -> "Partial Content"
81+
207 -> "Multi-Status"
82+
208 -> "Already Reported"
83+
226 -> "IM Used"
84+
300 -> "Multiple Choices"
85+
301 -> "Moved Permanently"
86+
302 -> "Found"
87+
303 -> "See Other"
88+
304 -> "Not Modified"
89+
305 -> "Use Proxy"
90+
306 -> "unused"
91+
307 -> "Temporary Redirect"
92+
308 -> "Permanent Redirect"
93+
400 -> "Bad Request"
94+
401 -> "Unauthorized"
95+
402 -> "Payment Required"
96+
403 -> "Forbidden"
97+
404 -> "Not Found"
98+
405 -> "Method Not Allowed"
99+
406 -> "Not Acceptable"
100+
407 -> "Proxy Authentication Required"
101+
408 -> "Request Timeout"
102+
409 -> "Conflict"
103+
410 -> "Gone"
104+
411 -> "Length Required"
105+
412 -> "Precondition Failed"
106+
413 -> "Content Too Large"
107+
414 -> "URI Too Long"
108+
415 -> "Unsupported Media Type"
109+
416 -> "Range Not Satisfiable"
110+
417 -> "Expectation Failed"
111+
418 -> "I'm a teapot"
112+
421 -> "Misdirected Request"
113+
422 -> "Unprocessable Content"
114+
423 -> "Locked"
115+
424 -> "Failed Dependency"
116+
425 -> "Too Early"
117+
426 -> "Upgrade Required"
118+
428 -> "Precondition Required"
119+
429 -> "Too Many Requests"
120+
431 -> "Request Header Fields Too Large"
121+
451 -> "Unavailable For Legal Reasons"
122+
500 -> "Internal Server Error"
123+
501 -> "Not Implemented"
124+
502 -> "Bad Gateway"
125+
503 -> "Service Unavailable"
126+
504 -> "Gateway Timeout"
127+
505 -> "HTTP Version Not Supported"
128+
506 -> "Variant Also Negotiates"
129+
507 -> "Insufficient Storage"
130+
508 -> "Loop Detected"
131+
510 -> "Not Extended"
132+
511 -> "Network Authentication Required"
133+
else -> "Unknown"
134+
}
135+
}
67136
}
68137

69138
fun WebView.isOutdated(): Boolean {

0 commit comments

Comments
 (0)