@@ -153,6 +153,45 @@ class MainActivity : AppCompatActivity() {
153153 }
154154 }
155155
156+ fun sendUnpinnedHttp3 (view : View ) {
157+ onStart(R .id.http3_unpinned)
158+ val context = this @MainActivity
159+
160+ val cronetEngine = org.chromium.net.CronetEngine .Builder (context)
161+ .enableQuic(true )
162+ .addQuicHint(" www.google.com" , 443 , 443 )
163+ .build()
164+ val requestBuilder = cronetEngine.newUrlRequestBuilder(
165+ " https://www.google.com/" ,
166+ object : org.chromium.net.UrlRequest .Callback () {
167+ override fun onRedirectReceived (request : org.chromium.net.UrlRequest , info : org.chromium.net.UrlResponseInfo , newLocationUrl : String ) {}
168+ override fun onReadCompleted (request : org.chromium.net.UrlRequest , info : org.chromium.net.UrlResponseInfo , byteBuffer : java.nio.ByteBuffer ) {}
169+ override fun onSucceeded (request : org.chromium.net.UrlRequest , info : org.chromium.net.UrlResponseInfo ) {}
170+
171+ override fun onResponseStarted (request : org.chromium.net.UrlRequest , info : org.chromium.net.UrlResponseInfo ) {
172+ request.cancel()
173+ if (info.negotiatedProtocol == " h3" ) {
174+ onSuccess(R .id.http3_unpinned)
175+ } else {
176+ onError(R .id.http3_unpinned, " Expected HTTP/3, got ${info.negotiatedProtocol} " )
177+ onSuccess(R .id.http3_unpinned)
178+ }
179+ }
180+
181+ override fun onFailed (request : org.chromium.net.UrlRequest , info : org.chromium.net.UrlResponseInfo ? , error : org.chromium.net.CronetException ) {
182+ println (" h3 request failed: $error " )
183+ onError(R .id.http3_unpinned, error.toString())
184+ }
185+ },
186+ java.util.concurrent.Executors .newSingleThreadExecutor()
187+ )
188+
189+ requestBuilder
190+ .disableCache()
191+ .build()
192+ .start()
193+ }
194+
156195 fun sendConfigPinned (view : View ) {
157196 GlobalScope .launch(Dispatchers .IO ) {
158197 onStart(R .id.config_pinned)
0 commit comments