google / cronet-transport-for-okhttp

This package allows OkHttp and Retrofit users to use Cronet as their transport layer, benefiting from features like QUIC/HTTP3 support or connection migration.
Apache License 2.0
427 stars 31 forks source link

The onFailure method is not called when http connection fails. #4

Closed hdjchh closed 2 years ago

hdjchh commented 2 years ago

The onFailure method should be called when http connection fails.


val core  = CronetEngine.Builder(applicationContext)
            .enableHttp2(true)
            .enableQuic(true)
            .addQuicHint("cloudflare-quic.com",443,443)
            .enableBrotli(true)
            .build()
        val okHttpClient = OkHttpClient().newBuilder()
            .addInterceptor(CronetInterceptor.newBuilder(core).build())
            .build()
        val quic=Request.Builder()
            .url("https://cloudflare-quic.com/")
            .build()
        okHttpClient.newCall(quic).enqueue(object : Callback {
            override fun onFailure(call: Call, e: IOException) {
                runOnUiThread{
                    Toast.makeText(applicationContext,"Failure!", Toast.LENGTH_SHORT).show()
                }
            }

            override fun onResponse(call: Call, response: Response) {
                runOnUiThread{
                    Toast.makeText(applicationContext,"Successful!", Toast.LENGTH_SHORT).show()
                }
            }
        })
hdjchh commented 2 years ago

It's okay because it was only when using a VPN.