Skip to content

Commit b74aea5

Browse files
committed
Properly log TLS failures in webview example
1 parent ff89e78 commit b74aea5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

app/src/main/java/tech/httptoolkit/pinning_demo/MainActivity.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class MainActivity : AppCompatActivity() {
113113
onStart(R.id.webview_unpinned)
114114
val webView = WebView(this@MainActivity)
115115

116+
var connectionFailed = false
117+
116118
webView.loadUrl("https://sha256.badssl.com")
117119
webView.webViewClient = object : WebViewClient() {
118120
override fun onReceivedSslError(
@@ -121,9 +123,13 @@ class MainActivity : AppCompatActivity() {
121123
error: SslError?
122124
) {
123125
onError(R.id.webview_unpinned, error.toString())
126+
connectionFailed = true
127+
handler?.cancel()
124128
}
125129

126130
override fun onPageFinished(view: WebView?, url: String?) {
131+
if (connectionFailed) return
132+
127133
println("Unpinned WebView loaded OK")
128134
onSuccess(R.id.webview_unpinned)
129135
}

0 commit comments

Comments
 (0)