Unverified Commit 4f3199f8 authored by Alexander Aprelev's avatar Alexander Aprelev Committed by GitHub

Update image_list example to use https instead of http (#39124)

* Update image_list test to use locally set up https server to validate performance of image loading over https(rather than http) protocol. Https requires more back-and-forward communication before image bytes are sent to the client, shows clear signs of throughput affected by how busy flutter UI isolate is.
parent 9749f59c
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'dart:math';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle; import 'package:flutter/services.dart' show rootBundle;
...@@ -14,19 +15,98 @@ import 'package:flutter/services.dart'; ...@@ -14,19 +15,98 @@ import 'package:flutter/services.dart';
/// image and prints how long the loading took. /// image and prints how long the loading took.
/// ///
/// This is used in [$FH/flutter/devicelab/bin/tasks/image_list_reported_duration.dart] test. /// This is used in [$FH/flutter/devicelab/bin/tasks/image_list_reported_duration.dart] test.
///
String certificate = '''
-----BEGIN CERTIFICATE-----
MIIDlTCCAn2gAwIBAgIUNfw2s1D9qwYw8bMEZ1rdNVQXi9YwDQYJKoZIhvcNAQEL
BQAwcjELMAkGA1UEBhMCVVMxETAPBgNVBAgMCE5ldyBZb3JrMRIwEAYDVQQHDAlS
b2NoZXN0ZXIxEjAQBgNVBAoMCWxvY2FsaG9zdDEUMBIGA1UECwwLRGV2ZWxvcG1l
bnQxEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0xOTA4MjIyMzMwMjdaFw0yMDA4MjEy
MzMwMjdaMHIxCzAJBgNVBAYTAlVTMREwDwYDVQQIDAhOZXcgWW9yazESMBAGA1UE
BwwJUm9jaGVzdGVyMRIwEAYDVQQKDAlsb2NhbGhvc3QxFDASBgNVBAsMC0RldmVs
b3BtZW50MRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IB
DwAwggEKAoIBAQCi/fmozdYuCI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4qXrD7DgeKAGnWteBJP
tmjmXXvDb1O19xArlv/N9WRiJAI6FvwPkPiNUvlLsz51m9uzjZgCLzqCE9cJR91/
erQT9ORBs7n7fTsfah+sZlA2u65ecF4mGHbwmccCgYAqHNRHnx1iHrYfr97cmXc9
fNjJ7e1NHhVdgpGjaOiBSKj2rHNRy6iwCNbs5wjmRWlgqnFEM5r0VfFn9L0PvcQK
7iExMTm/PkSqHUntpy82Q8zRWmhw0G5p9DYyIPtaeW1NIKpIlCw6dTlf750BiGkr
mhBKvYQc85gja0s1c+1VXA==
-----END PRIVATE KEY-----
''';
class MyHttpOverrides extends HttpOverrides {
@override
HttpClient createHttpClient(SecurityContext context) {
return super.createHttpClient(
(context ?? SecurityContext())..setTrustedCertificatesBytes(certificate.codeUnits)
);
}
}
Future<void> main() async { Future<void> main() async {
HttpOverrides.global = MyHttpOverrides();
final SecurityContext serverContext = SecurityContext()
..useCertificateChainBytes(certificate.codeUnits)
..usePrivateKeyBytes(privateKey.codeUnits);
final HttpServer httpServer = final HttpServer httpServer =
await HttpServer.bind(InternetAddress.anyIPv6, 0); await HttpServer.bindSecure('localhost', 0, serverContext);
final int port = httpServer.port; final int port = httpServer.port;
print('Listening on port $port.'); print('Listening on port $port.');
// Initializes bindings before using any platform channels. // Initializes bindings before using any platform channels.
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
final ByteData byteData = await rootBundle.load('images/coast.jpg'); final ByteData byteData = await rootBundle.load('images/coast.jpg');
final Uint8List bytes = byteData.buffer
.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes);
httpServer.listen((HttpRequest request) async { httpServer.listen((HttpRequest request) async {
const int chunk_size = 2048;
int offset = byteData.offsetInBytes;
while (offset < byteData.lengthInBytes) {
final int length = min(byteData.lengthInBytes - offset, chunk_size);
final Uint8List bytes = byteData.buffer.asUint8List(offset, length);
offset += length;
request.response.add(bytes); request.response.add(bytes);
// Let other isolates and microtasks to run.
await Future<void>.delayed(const Duration());
}
request.response.close(); request.response.close();
}); });
...@@ -73,7 +153,7 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin { ...@@ -73,7 +153,7 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
Widget createImage(final int index, final Completer<bool> completer) { Widget createImage(final int index, final Completer<bool> completer) {
return Image.network( return Image.network(
'http://localhost:${widget.port}/${_counter * IMAGES + index}', 'https://localhost:${widget.port}/${_counter * IMAGES + index}',
frameBuilder: ( frameBuilder: (
BuildContext context, BuildContext context,
Widget child, Widget child,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment