Merge pull request #36 from dart-lang/any

Bind to the correct address for `any`
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3368ca3..1f0072d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 3.0.1
+
+* Fix an issue where `bind` would bind to the `anyIPv6` address in unsupported
+  environments.
+
 ## 3.0.0
 
 * Migrate to null safety.
diff --git a/lib/http_multi_server.dart b/lib/http_multi_server.dart
index bd8a6a7..7fdc2d6 100644
--- a/lib/http_multi_server.dart
+++ b/lib/http_multi_server.dart
@@ -133,21 +133,31 @@
   /// Bind an [HttpServer] with handling for special addresses 'localhost' and
   /// 'any'.
   ///
-  /// For address 'localhost' behaves like [loopback]. For 'any' listens on
-  /// [InternetAddress.anyIPv6] which listens on all hostnames for both IPv4 and
-  /// IPV6. For any other address forwards directly to `HttpServer.bind` where
+  /// For address 'localhost' behaves like [loopback].
+  ///
+  /// For 'any' listens on [InternetAddress.anyIPv6] if the system supports IPv6
+  /// otherwise [InternetAddress.anyIPv4]. Note [InternetAddress.anyIPv6]
+  /// listens on all hostnames for both IPv4 and IPv6.
+  ///
+  /// For any other address forwards directly to `HttpServer.bind` where
   /// the IPvX support may vary.
   ///
   /// See [HttpServer.bind].
   static Future<HttpServer> bind(dynamic address, int port,
-      {int backlog = 0, bool v6Only = false, bool shared = false}) {
+      {int backlog = 0, bool v6Only = false, bool shared = false}) async {
     if (address == 'localhost') {
       return HttpMultiServer.loopback(port,
           backlog: backlog, v6Only: v6Only, shared: shared);
     }
     if (address == 'any') {
-      return HttpServer.bind(InternetAddress.anyIPv6, port,
-          backlog: backlog, v6Only: v6Only, shared: shared);
+      return HttpServer.bind(
+          await supportsIPv6
+              ? InternetAddress.anyIPv6
+              : InternetAddress.anyIPv4,
+          port,
+          backlog: backlog,
+          v6Only: v6Only,
+          shared: shared);
     }
     return HttpServer.bind(address, port,
         backlog: backlog, v6Only: v6Only, shared: shared);
diff --git a/pubspec.yaml b/pubspec.yaml
index 33f2f91..1f0c301 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: http_multi_server
-version: 3.0.0
+version: 3.0.1
 
 description: >-
   A dart:io HttpServer wrapper that handles requests from multiple servers.
diff --git a/test/http_multi_server_test.dart b/test/http_multi_server_test.dart
index 749980e..29c624f 100644
--- a/test/http_multi_server_test.dart
+++ b/test/http_multi_server_test.dart
@@ -219,6 +219,16 @@
       }
     });
 
+    test("uses the correct server address for 'any'", () async {
+      final server = await HttpMultiServer.bind('any', 0);
+
+      if (!await supportsIPv6) {
+        expect(server.address, InternetAddress.anyIPv4);
+      } else {
+        expect(server.address, InternetAddress.anyIPv6);
+      }
+    });
+
     test('listens on specified hostname', () async {
       if (!await supportsIPv4) return;
       final server = await HttpMultiServer.bind(InternetAddress.anyIPv4, 0);