From c4f707e6491617ad8f9d0ed19dab70cf5a537f98 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 25 Sep 2020 23:17:45 -0400 Subject: [PATCH 1/4] Fix outdated mini_file_server.dart Issue - https://github.com/dart-lang/site-www/issues/2646 - Propose to fix mini server example continuous loop on the connection. --- httpserver/bin/mini_file_server.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/httpserver/bin/mini_file_server.dart b/httpserver/bin/mini_file_server.dart index 2e8bff6..840a986 100644 --- a/httpserver/bin/mini_file_server.dart +++ b/httpserver/bin/mini_file_server.dart @@ -16,7 +16,7 @@ var targetFile = File(p.join(p.dirname(Platform.script.toFilePath()), 'index.html')); Future main() async { - var server; + Stream server; try { server = await HttpServer.bind(InternetAddress.loopbackIPv4, 4044); @@ -39,7 +39,7 @@ Future main() async { } else { print("Can't open ${targetFile.path}."); req.response.statusCode = HttpStatus.notFound; - await req.response.close(); } + await req.response.close(); } } From 8e90444ec5124224daf2cd2df6b1ffa27c96d3c5 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 25 Sep 2020 23:41:44 -0400 Subject: [PATCH 2/4] Update mini_file_server.dart --- httpserver/bin/mini_file_server.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpserver/bin/mini_file_server.dart b/httpserver/bin/mini_file_server.dart index 840a986..4dc76eb 100644 --- a/httpserver/bin/mini_file_server.dart +++ b/httpserver/bin/mini_file_server.dart @@ -24,7 +24,7 @@ Future main() async { print("Couldn't bind to port 4044: $e"); exit(-1); } - print('Listening on http://${server.address.address}:${server.port}/'); + print('Listening on http://localhost:4044/'); await for (HttpRequest req in server) { if (await targetFile.exists()) { From 50c081ccd883b0dcf63f57235f29ede073b82329 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 16 Oct 2020 14:18:26 -0400 Subject: [PATCH 3/4] Added dart type loopbackIPv4 to server response To resolve the dart type issues within the print statement feedback on the server response. Expected response `Listening on 127.0.0.1:4044` on call instead of `Listening on localhost:4044` --- httpserver/bin/mini_file_server.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpserver/bin/mini_file_server.dart b/httpserver/bin/mini_file_server.dart index 4dc76eb..3e964de 100644 --- a/httpserver/bin/mini_file_server.dart +++ b/httpserver/bin/mini_file_server.dart @@ -24,7 +24,7 @@ Future main() async { print("Couldn't bind to port 4044: $e"); exit(-1); } - print('Listening on http://localhost:4044/'); + print("Listening on ${InternetAddress.loopbackIPv4.address}:4044"); await for (HttpRequest req in server) { if (await targetFile.exists()) { From 921792862ee113c1d91807978e14d0c1c0c84504 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 23 Oct 2020 11:29:41 -0400 Subject: [PATCH 4/4] edit mini_file_server.dart I've edited single quotes for example file instead of double based on conversation. These can be merged. --- httpserver/bin/mini_file_server.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/httpserver/bin/mini_file_server.dart b/httpserver/bin/mini_file_server.dart index 3e964de..a4b7122 100644 --- a/httpserver/bin/mini_file_server.dart +++ b/httpserver/bin/mini_file_server.dart @@ -21,23 +21,23 @@ Future main() async { try { server = await HttpServer.bind(InternetAddress.loopbackIPv4, 4044); } catch (e) { - print("Couldn't bind to port 4044: $e"); + print('Could not bind to port 4044: $e'); exit(-1); } - print("Listening on ${InternetAddress.loopbackIPv4.address}:4044"); + print('Listening on ${InternetAddress.loopbackIPv4.address}:4044'); await for (HttpRequest req in server) { if (await targetFile.exists()) { - print("Serving ${targetFile.path}."); + print('Serving ${targetFile.path}.'); req.response.headers.contentType = ContentType.html; try { await req.response.addStream(targetFile.openRead()); } catch (e) { - print("Couldn't read file: $e"); + print('Could not read file: $e'); exit(-1); } } else { - print("Can't open ${targetFile.path}."); + print('Could not open ${targetFile.path}.'); req.response.statusCode = HttpStatus.notFound; } await req.response.close();