OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library unittest.util.io; | 5 library unittest.util.io; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 /// [fn] completes to. | 46 /// [fn] completes to. |
47 Future withTempDir(Future fn(String path)) { | 47 Future withTempDir(Future fn(String path)) { |
48 return new Future.sync(() { | 48 return new Future.sync(() { |
49 // TODO(nweiz): Empirically test whether sync or async functions perform | 49 // TODO(nweiz): Empirically test whether sync or async functions perform |
50 // better here when starting a bunch of isolates. | 50 // better here when starting a bunch of isolates. |
51 var tempDir = Directory.systemTemp.createTempSync('unittest_'); | 51 var tempDir = Directory.systemTemp.createTempSync('unittest_'); |
52 return new Future.sync(() => fn(tempDir.path)) | 52 return new Future.sync(() => fn(tempDir.path)) |
53 .whenComplete(() => tempDir.deleteSync(recursive: true)); | 53 .whenComplete(() => tempDir.deleteSync(recursive: true)); |
54 }); | 54 }); |
55 } | 55 } |
56 | |
57 /// Creates a URL string for [address]:[port]. | |
58 /// | |
59 /// Handles properly formatting IPv6 addresses. | |
60 Uri baseUrlForAddress(InternetAddress address, int port) { | |
61 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.
| |
62 return new Uri(scheme: "http", host: "localhost", port: port); | |
63 } | |
64 | |
65 // IPv6 addresses in URLs need to be enclosed in square brackets to avoid | |
66 // URL ambiguity with the ":" in the address. | |
67 if (address.type == InternetAddressType.IP_V6) { | |
68 return new Uri(scheme: "http", host: "[${address.address}]", port: port); | |
69 } | |
70 | |
71 return new Uri(scheme: "http", host: address.address, port: port); | |
72 } | |
OLD | NEW |