Address a number of open issues.

Fix example in README.md (#20) Add missing import in io_io.dart (#18);

Add error message when trying to load resource that cannot be resolved (#17),
instead of just failing when trying to use a `null` URI.

Make HttpClient be shared and reduce max number of connections to same server.
Hopefully this addresses #19. If not, the program really needs more
file descriptors than the OS provides.

R=floitsch@google.com

Review-Url: https://codereview.chromium.org//2666013004 .
diff --git a/CHANGELOG.md b/CHANGELOG.md
index faf031d..b257ba5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
 # Changelog
 
+## 2.1.1
+- Reduce max concurrent connections to the same host to 6 when using `dart:io`.
+  That's the same limit that many browsers use.
+- Trying to load a resource from a non-existing package now gives a better
+  error message.
+
 ## 2.1.0
 - Make failing HTTP requests throw an `HttpException`.
 
diff --git a/README.md b/README.md
index 8241d16..48af528 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@
 
 main() async {
   var resource = new Resource("package:foo/foo_data.txt");
-  var string = await resource.readAsString(UTF8);
+  var string = await resource.readAsString(encoding: UTF8);
   print(string);
 }
 ```
diff --git a/lib/src/io_io.dart b/lib/src/io_io.dart
index 1056d75..619dfed 100644
--- a/lib/src/io_io.dart
+++ b/lib/src/io_io.dart
@@ -9,6 +9,7 @@
                       HttpClient,
                       HttpClientResponse,
                       HttpClientRequest,
+                      HttpException,
                       HttpHeaders;
 
 import "package:typed_data/typed_buffers.dart" show Uint8Buffer;
@@ -90,9 +91,11 @@
   throw new UnsupportedError("Unsupported scheme: $uri");
 }
 
+HttpClient _sharedHttpClient = new HttpClient()..maxConnectionsPerHost = 6;
+
 Future<HttpClientResponse> _httpGetBytes(Uri uri) async {
-  HttpClientRequest request = await new HttpClient().getUrl(uri);
-    request.headers.set(HttpHeaders.ACCEPT, "application/octet-stream, */*");
+  HttpClientRequest request = await _sharedHttpClient.getUrl(uri);
+  request.headers.set(HttpHeaders.ACCEPT, "application/octet-stream, */*");
   return request.close();
 }
 
diff --git a/lib/src/resolve.dart b/lib/src/resolve.dart
index 7a54520..053899a 100644
--- a/lib/src/resolve.dart
+++ b/lib/src/resolve.dart
@@ -6,9 +6,14 @@
 import "dart:isolate" show Isolate;
 
 /// Helper function for resolving to a non-relative, non-package URI.
-Future<Uri> resolveUri(Uri uri) async {
+Future<Uri> resolveUri(Uri uri) {
   if (uri.scheme == "package") {
-    return Isolate.resolvePackageUri(uri);
+    return Isolate.resolvePackageUri(uri).then((resolvedUri) {
+      if (resolvedUri == null) {
+        throw new ArgumentError.value(uri, "uri", "Unknown package");
+      }
+      return resolvedUri;
+    });
   }
-  return Uri.base.resolveUri(uri);
+  return new Future<Uri>.value(Uri.base.resolveUri(uri));
 }
diff --git a/lib/src/resource_loader.dart b/lib/src/resource_loader.dart
index 3e0c78c..cdc8e77 100644
--- a/lib/src/resource_loader.dart
+++ b/lib/src/resource_loader.dart
@@ -6,8 +6,8 @@
 import "dart:convert" show Encoding;
 import "package_loader.dart";
 import "io_none.dart"
-    if (dart.library.io) "io_io.dart"
     if (dart.library.html) "io_html.dart"
+    if (dart.library.io) "io_io.dart"
     as io;
 
 /// Resource loading strategy.
diff --git a/pubspec.yaml b/pubspec.yaml
index 7a182b2..b15729e 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: resource
-version: 2.1.0
+version: 2.1.1
 description: Reading resource data from (package and other) files.
 author: Dart Team <misc@dartlang.org>
 homepage: https://github.com/dart-lang/resource
diff --git a/test/resource_test.dart b/test/resource_test.dart
index dbce947..608943a 100644
--- a/test/resource_test.dart
+++ b/test/resource_test.dart
@@ -39,8 +39,8 @@
     }
 
     test("load package: URIs", () async {
-      await testLoad(pkguri("foo/bar/baz"));
-      await testLoad(pkguri("bar/foo/baz"));
+      await testLoad(pkguri("resource/bar/baz"));
+      await testLoad(pkguri("test/foo/baz"));
     });
     test("load non-pkgUri", () async {
       await testLoad(Uri.parse("file://localhost/something?x#y"));