Use default-port-aware URI comparisons in pub.

This fixes a usability issue where error messages from
pub.dartlang.org were getting reported as generic HTTP errors.

Review URL: https://codereview.chromium.org//12667016

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@19826 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
nweiz@google.com 2013-03-11 23:07:17 +00:00
parent e3192492c9
commit f29ae528f7
3 changed files with 20 additions and 3 deletions

View file

@ -85,12 +85,12 @@ class LishCommand extends PubCommand {
}).catchError((asyncError) {
if (asyncError.error is! PubHttpException) throw asyncError;
var url = asyncError.error.response.request.url;
if (url.toString() == cloudStorageUrl.toString()) {
if (uriEqual(url, cloudStorageUrl)) {
// TODO(nweiz): the response may have XML-formatted information about
// the error. Try to parse that out once we have an easily-accessible
// XML parser.
throw 'Failed to upload the package.';
} else if (url.origin == server.origin) {
} else if (uriEqual(url.origin, server.origin)) {
handleJsonError(asyncError.error.response);
} else {
throw asyncError;

View file

@ -52,7 +52,8 @@ class PubHttpClient extends http.BaseClient {
// 401 responses should be handled by the OAuth2 client. It's very
// unlikely that they'll be returned by non-OAuth2 requests. We also want
// to pass along 400 responses from the token endpoint.
var tokenRequest = streamedResponse.request.url == oauth2.tokenEndpoint;
var tokenRequest = urisEqual(
streamedResponse.request.url, oauth2.tokenEndpoint);
if (status < 400 || status == 401 || (status == 400 && tokenRequest)) {
return streamedResponse;
}

View file

@ -310,6 +310,22 @@ String mapToQuery(Map<String, String> map) {
}).join("&");
}
// TODO(nweiz): remove this when issue 9068 has been fixed.
/// Whether [uri1] and [uri2] are equal. This consider HTTP URIs to default to
/// port 80, and HTTPs URIs to default to port 443.
bool urisEqual(Uri uri1, Uri uri2) =>
canonicalizeUri(uri1) == canonicalizeUri(uri2);
/// Return [uri] with redundant port information removed.
Uri canonicalizeUri(Uri uri) {
var sansPort = new Uri.fromComponents(
scheme: uri.scheme, userInfo: uri.userInfo, domain: uri.domain,
path: uri.path, query: uri.query, fragment: uri.fragment);
if (uri.scheme == 'http' && uri.port == 80) return sansPort;
if (uri.scheme == 'https' && uri.port == 443) return sansPort;
return uri;
}
/// Add all key/value pairs from [source] to [destination], overwriting any
/// pre-existing values.
void mapAddAll(Map destination, Map source) =>