Chromium Code Reviews| Index: lib/src/util/io.dart |
| diff --git a/lib/src/util/io.dart b/lib/src/util/io.dart |
| index 8a4a9036c766984ad7e2b1293decc6960ba3f7bd..1cf51104d023d95657ce5f8037087f3cb2dde4b3 100644 |
| --- a/lib/src/util/io.dart |
| +++ b/lib/src/util/io.dart |
| @@ -53,3 +53,20 @@ Future withTempDir(Future fn(String path)) { |
| .whenComplete(() => tempDir.deleteSync(recursive: true)); |
| }); |
| } |
| + |
| +/// Creates a URL string for [address]:[port]. |
| +/// |
| +/// Handles properly formatting IPv6 addresses. |
| +Uri baseUrlForAddress(InternetAddress address, int port) { |
| + if (address.isLoopback) { |
|
Bob Nystrom
2015/02/27 21:51:40
What if it's an IPv6 loopback?
nweiz
2015/02/28 00:42:05
"localhost" is still valid.
|
| + return new Uri(scheme: "http", host: "localhost", port: port); |
| + } |
| + |
| + // IPv6 addresses in URLs need to be enclosed in square brackets to avoid |
| + // URL ambiguity with the ":" in the address. |
| + if (address.type == InternetAddressType.IP_V6) { |
| + return new Uri(scheme: "http", host: "[${address.address}]", port: port); |
| + } |
| + |
| + return new Uri(scheme: "http", host: address.address, port: port); |
| +} |