blob: 4be5ef8303f54a98d3f913b83877b5fb9991e564 [file] [log] [blame]
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// @assertion Future close({bool force: false})
/// Permanently stops this HttpServer from listening for new connections. This
/// closes the Stream of HttpRequests with a done event. The returned future
/// completes when the server is stopped. For a server started using bind or
/// bindSecure this means that the port listened on no longer in use.
///
/// If force is true, active connections will be closed immediately.
/// @description Checks that this method closes the Stream of HttpRequests with a
/// done event
/// @author sgrekhov@unipro.ru
import "dart:io";
import "dart:convert";
import "../../../Utils/expect.dart";
test() async {
String helloWorld = 'Hello, test world!';
HttpServer server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
asyncStart();
server.listen((HttpRequest request) {
request.response.write(helloWorld);
request.response.close();
server.close();
}).onDone(() {
asyncEnd();
});
asyncStart();
HttpClient client = new HttpClient();
client
.getUrl(Uri.parse(
"http://${InternetAddress.loopbackIPv4.address}:${server.port}"))
.then((HttpClientRequest request) {
return request.close();
}).then((HttpClientResponse response) {
Expect.equals(HttpStatus.ok, response.statusCode);
response.cast<List<int>>().transform(utf8.decoder).listen((content) {
Expect.equals(helloWorld, content);
asyncEnd();
});
});
asyncEnd();
}
main() {
asyncStart();
test();
}