Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: utils/pub/http.dart

Issue 12042053: Get rid of unneeded Future.immediate() calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /// Helpers for dealing with HTTP. 5 /// Helpers for dealing with HTTP.
6 library pub.http; 6 library pub.http;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:json' as json; 10 import 'dart:json' as json;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 // TODO(nweiz): Ideally the timeout would extend to reading from the 44 // TODO(nweiz): Ideally the timeout would extend to reading from the
45 // response input stream, but until issue 3657 is fixed that's not feasible. 45 // response input stream, but until issue 3657 is fixed that's not feasible.
46 return timeout(inner.send(request).then((streamedResponse) { 46 return timeout(inner.send(request).then((streamedResponse) {
47 log.fine("Got response ${streamedResponse.statusCode} " 47 log.fine("Got response ${streamedResponse.statusCode} "
48 "${streamedResponse.reasonPhrase}."); 48 "${streamedResponse.reasonPhrase}.");
49 49
50 var status = streamedResponse.statusCode; 50 var status = streamedResponse.statusCode;
51 // 401 responses should be handled by the OAuth2 client. It's very 51 // 401 responses should be handled by the OAuth2 client. It's very
52 // unlikely that they'll be returned by non-OAuth2 requests. 52 // unlikely that they'll be returned by non-OAuth2 requests.
53 if (status < 400 || status == 401) { 53 if (status < 400 || status == 401) return streamedResponse;
54 return new Future.immediate(streamedResponse);
55 }
56 54
57 return http.Response.fromStream(streamedResponse).then((response) { 55 return http.Response.fromStream(streamedResponse).then((response) {
58 throw new PubHttpException(response); 56 throw new PubHttpException(response);
59 }); 57 });
60 }).catchError((asyncError) { 58 }).catchError((asyncError) {
61 if (asyncError.error is SocketIOException && 59 if (asyncError.error is SocketIOException &&
62 asyncError.error.osError != null && 60 asyncError.error.osError != null &&
63 (asyncError.error.osError.errorCode == 8 || 61 (asyncError.error.osError.errorCode == 8 ||
64 asyncError.error.osError.errorCode == -2 || 62 asyncError.error.osError.errorCode == -2 ||
65 asyncError.error.osError.errorCode == -5 || 63 asyncError.error.osError.errorCode == -5 ||
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 125
128 /// Exception thrown when an HTTP operation fails. 126 /// Exception thrown when an HTTP operation fails.
129 class PubHttpException implements Exception { 127 class PubHttpException implements Exception {
130 final http.Response response; 128 final http.Response response;
131 129
132 const PubHttpException(this.response); 130 const PubHttpException(this.response);
133 131
134 String toString() => 'HTTP error ${response.statusCode}: ' 132 String toString() => 'HTTP error ${response.statusCode}: '
135 '${response.reasonPhrase}'; 133 '${response.reasonPhrase}';
136 } 134 }
OLDNEW
« utils/pub/entrypoint.dart ('K') | « utils/pub/git_source.dart ('k') | utils/pub/io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698