Skip to content

Commit 40e17a7

Browse files
committed
Browser : Prevent proxy / DoH load failures URL from being loaded by the browser + make sure XHR & Fetch requests follow DoH settings
1 parent 02c7424 commit 40e17a7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

app/src/main/java/me/devsaki/hentoid/activities/sources/BaseBrowserActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ abstract class BaseBrowserActivity : BaseActivity(), CustomWebViewClient.Browser
586586
if (BuildConfig.DEBUG) WebView.setWebContentsDebuggingEnabled(true)
587587
webClient = createWebClient()
588588
webView.webViewClient = webClient
589-
if (getStartSite().useManagedRequests || Settings.proxy.isNotEmpty()) {
589+
if (getStartSite().useManagedRequests || Settings.proxy.isNotEmpty() || Settings.dnsOverHttps > -1) {
590590
xhrHandler = { url, body -> webClient.recordDynamicPostRequests(url, body) }
591591
fetchHandler = { url, body -> webClient.recordDynamicPostRequests(url, body) }
592592
}

app/src/main/java/me/devsaki/hentoid/activities/sources/CustomWebViewClient.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -598,19 +598,24 @@ open class CustomWebViewClient : WebViewClient {
598598
)
599599
res.use { response ->
600600
// Scram if the response is a redirection or an error
601-
if (response.code >= 300) return null
601+
if (response.code >= 300) {
602+
Timber.v("sendRequest ${request.method} ${request.url} FAILED ${response.code}")
603+
return WebResourceResponse(
604+
"text/plain",
605+
"utf-8",
606+
ByteArrayInputStream(NOTHING)
607+
)
608+
}
602609
response.body.byteStream().use {
603610
val streams = duplicateInputStream(it, 1)
604611
return okHttpResponseToWebkitResponse(response, streams[0])
605612
}
606613
}
607-
} catch (e: IOException) {
608-
Timber.i(e)
609-
} catch (e: IllegalStateException) {
610-
Timber.i(e)
614+
} catch (e: Exception) {
615+
Timber.i(e, "sendRequest ${request.method} ${request.url} failed ")
611616
}
612617
}
613-
return null
618+
return WebResourceResponse("text/plain", "utf-8", ByteArrayInputStream(NOTHING))
614619
}
615620

616621
fun recordDynamicPostRequests(url: String, body: String) {

0 commit comments

Comments
 (0)