Migrated http_ipv6_test from SDK. (#50)
* Migrated http_ipv6_test from SDK.
* Enable IPv6 for Travis
diff --git a/.travis.yml b/.travis.yml
index b48179e..0f61077 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,13 @@
language: dart
sudo: false
+before_script:
+ # Add an IPv6 config - see the corresponding Travis issue
+ # https://github.com/travis-ci/travis-ci/issues/8361
+ - if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
+ sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6';
+ fi
+
dart:
- stable
- dev
diff --git a/test/http_ipv6_test.dart b/test/http_ipv6_test.dart
new file mode 100644
index 0000000..f2135b3
--- /dev/null
+++ b/test/http_ipv6_test.dart
@@ -0,0 +1,41 @@
+// (c) 2018, 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.
+
+import 'dart:async';
+
+import 'package:http_io/http_io.dart';
+import 'package:test/test.dart';
+
+// Client makes a HTTP 1.0 request without connection keep alive. The
+// server sets a content length but still needs to close the
+// connection as there is no keep alive.
+Future<Null> testHttpIPv6() {
+ final completer = new Completer<Null>();
+ HttpServer.bind("::", 0).then((server) {
+ server.listen((HttpRequest request) {
+ expect(request.headers["host"][0], equals("[::1]:${server.port}"));
+ expect(request.requestedUri.host, equals("::1"));
+ request.response.close();
+ });
+
+ var client = new HttpClient();
+ var url = Uri.parse('http://[::1]:${server.port}/xxx');
+ expect(url.host, equals('::1'));
+ client
+ .openUrl('GET', url)
+ .then((request) => request.close())
+ .then((response) {
+ expect(response.statusCode, equals(HttpStatus.OK));
+ }).whenComplete(() {
+ server.close();
+ client.close();
+ completer.complete();
+ });
+ });
+ return completer.future;
+}
+
+void main() {
+ test('httpIPv6', testHttpIPv6);
+}