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

View File

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