1
0
Fork 0

Move teapot response to separate function

This commit is contained in:
Alex Kotov 2021-08-17 04:14:08 +05:00 committed by GitHub
parent a73913bdb4
commit 18d36e1ae4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,10 +20,7 @@ class CustomWebViewClient(private val context: Context) : WebViewClient() {
): WebResourceResponse? {
if (!relatedHost(request)) return super.shouldInterceptRequest(view, request)
if (!validComponents(request)) return WebResourceResponse(
"text/plain", "utf-8", 418, "I'm a teapot",
null, null,
)
if (!validComponents(request)) return teapotResponse()
return when (request.url.path) {
"/assets/images/blog/decentralized-vs-distributed-wrong.png" ->
@ -33,10 +30,7 @@ class CustomWebViewClient(private val context: Context) : WebViewClient() {
WebResourceResponse("image/png", "utf-8",
context.assets.open("network-topologies.png"))
else ->
WebResourceResponse(
"text/plain", "utf-8", 418, "I'm a teapot",
null, null,
)
teapotResponse()
}
}
@ -51,4 +45,11 @@ class CustomWebViewClient(private val context: Context) : WebViewClient() {
request.url.query == null &&
request.url.fragment == null
}
private fun teapotResponse(): WebResourceResponse {
return WebResourceResponse(
"text/plain", "utf-8", 418, "I'm a teapot",
null, null,
)
}
}