feat: upate secure_server/simple_secure_server.dart

This commit is contained in:
2021-04-24 22:00:30 +08:00
parent a1f5ee3935
commit d9772727c9
2 changed files with 9 additions and 5 deletions

1
.gitignore vendored
View File

@@ -1,6 +1,7 @@
# ---> Dart # ---> Dart
# See https://www.dartlang.org/guides/libraries/private-files # See https://www.dartlang.org/guides/libraries/private-files
.idea/
# Files and directories created by pub # Files and directories created by pub
.dart_tool/ .dart_tool/
.packages .packages

View File

@@ -5,19 +5,22 @@ String serverKey = 'server_key.pem';
Future main() async { Future main() async {
var serverContext = SecurityContext(); var serverContext = SecurityContext();
serverContext.useCertificateChain(certificateChain); serverContext
serverContext.usePrivateKey(serverKey, password: 'dartdart'); ..useCertificateChain(certificateChain)
..usePrivateKey(serverKey, password: 'dartdart');
var server = await HttpServer.bindSecure( var server = await HttpServer.bindSecure(
'0.0.0.0', '0.0.0.0',
8443, 8443,
serverContext, serverContext,
); );
print('Listening on localhost:${server.port}'); print('[INFO] Listening on localhost:${server.port} for HTTPS requests');
await for (HttpRequest request in server) { await for (HttpRequest request in server) {
print('Got request for ${request.uri.path}'); print('[INFO] Got request for ${request.uri.path}');
request.response request.response
..write('Hello, world!') ..statusCode = 200
..headers.add("content-type", "text/plain; charset=utf-8")
..write('Hello, world!\n')
..close(); ..close();
} }
} }