| OLD | NEW |
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) { |
| 54 return new Future.immediate(streamedResponse); | 54 return new Future.immediate(streamedResponse); |
| 55 } | 55 } |
| 56 | 56 |
| 57 return http.Response.fromStream(streamedResponse).then((response) { | 57 return http.Response.fromStream(streamedResponse).then((response) { |
| 58 throw new PubHttpException(response); | 58 throw new PubHttpException(response); |
| 59 }); | 59 }); |
| 60 }).catchError((asyncError) { | 60 }).catchError((asyncError) { |
| 61 var e = getRealError(asyncError); | 61 if (asyncError.error is SocketIOException && |
| 62 if (e is SocketIOException && | 62 asyncError.error.osError != null && |
| 63 e.osError != null && | 63 (asyncError.error.osError.errorCode == 8 || |
| 64 (e.osError.errorCode == 8 || | 64 asyncError.error.osError.errorCode == -2 || |
| 65 e.osError.errorCode == -2 || | 65 asyncError.error.osError.errorCode == -5 || |
| 66 e.osError.errorCode == -5 || | 66 asyncError.error.osError.errorCode == 11004)) { |
| 67 e.osError.errorCode == 11004)) { | |
| 68 throw 'Could not resolve URL "${request.url.origin}".'; | 67 throw 'Could not resolve URL "${request.url.origin}".'; |
| 69 } | 68 } |
| 70 throw asyncError; | 69 throw asyncError; |
| 71 }), HTTP_TIMEOUT, 'fetching URL "${request.url}"'); | 70 }), HTTP_TIMEOUT, 'fetching URL "${request.url}"'); |
| 72 } | 71 } |
| 73 } | 72 } |
| 74 | 73 |
| 75 /// The HTTP client to use for all HTTP requests. | 74 /// The HTTP client to use for all HTTP requests. |
| 76 final httpClient = new PubHttpClient(); | 75 final httpClient = new PubHttpClient(); |
| 77 | 76 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 127 |
| 129 /// Exception thrown when an HTTP operation fails. | 128 /// Exception thrown when an HTTP operation fails. |
| 130 class PubHttpException implements Exception { | 129 class PubHttpException implements Exception { |
| 131 final http.Response response; | 130 final http.Response response; |
| 132 | 131 |
| 133 const PubHttpException(this.response); | 132 const PubHttpException(this.response); |
| 134 | 133 |
| 135 String toString() => 'HTTP error ${response.statusCode}: ' | 134 String toString() => 'HTTP error ${response.statusCode}: ' |
| 136 '${response.reasonPhrase}'; | 135 '${response.reasonPhrase}'; |
| 137 } | 136 } |
| OLD | NEW |