Chromium Code Reviews| 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 library curl_client; | 5 library curl_client; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import '../../pkg/http/lib/http.dart' as http; | 9 import '../../pkg/http/lib/http.dart' as http; |
| 10 import 'io.dart'; | 10 import 'io.dart'; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 // If there's not going to be a response body (e.g. for HEAD requests), curl | 128 // If there's not going to be a response body (e.g. for HEAD requests), curl |
| 129 // prints the headers to stdout instead of the body. We want to wait until | 129 // prints the headers to stdout instead of the body. We want to wait until |
| 130 // all the headers are received to read them from the header file. | 130 // all the headers are received to read them from the header file. |
| 131 if (!expectBody) { | 131 if (!expectBody) { |
| 132 return Futures.wait([ | 132 return Futures.wait([ |
| 133 consumeInputStream(process.stdout), | 133 consumeInputStream(process.stdout), |
| 134 exitFuture | 134 exitFuture |
| 135 ]); | 135 ]); |
| 136 } | 136 } |
| 137 | 137 |
| 138 // TODO(nweiz): remove this when issue 4061 is fixed. | |
| 139 var stackTrace; | |
| 140 try { | |
| 141 throw null; | |
|
Bob Nystrom
2012/11/29 22:25:40
Throwing null is forbidden and causes a different
nweiz
2012/11/29 22:39:02
Done.
| |
| 142 } catch (_, localStackTrace) { | |
| 143 stackTrace = localStackTrace; | |
| 144 } | |
| 145 | |
| 138 var completer = new Completer(); | 146 var completer = new Completer(); |
| 139 resetCallbacks() { | 147 resetCallbacks() { |
| 140 process.stdout.onData = null; | 148 process.stdout.onData = null; |
| 141 process.stdout.onError = null; | 149 process.stdout.onError = null; |
| 142 process.stdout.onClosed = null; | 150 process.stdout.onClosed = null; |
| 143 } | 151 } |
| 144 process.stdout.onData = () { | 152 process.stdout.onData = () { |
| 145 // TODO(nweiz): If an error happens after the body data starts being | 153 // TODO(nweiz): If an error happens after the body data starts being |
| 146 // received, it should be piped through Response.stream once issue | 154 // received, it should be piped through Response.stream once issue |
| 147 // 3657 is fixed. | 155 // 3657 is fixed. |
| 148 exitFuture.handleException((e) => true); | 156 exitFuture.handleException((e) => true); |
| 149 resetCallbacks(); | 157 resetCallbacks(); |
| 150 completer.complete(null); | 158 completer.complete(null); |
| 151 }; | 159 }; |
| 152 process.stdout.onError = (e) { | 160 process.stdout.onError = (e) { |
| 153 resetCallbacks(); | 161 resetCallbacks(); |
| 154 completer.completeException(e); | 162 completer.completeException(e, stackTrace); |
| 155 }; | 163 }; |
| 156 process.stdout.onClosed = () { | 164 process.stdout.onClosed = () { |
| 157 resetCallbacks(); | 165 resetCallbacks(); |
| 158 chainToCompleter(exitFuture, completer); | 166 chainToCompleter(exitFuture, completer); |
| 159 }; | 167 }; |
| 160 return completer.future; | 168 return completer.future; |
| 161 } | 169 } |
| 162 | 170 |
| 163 /// Returns a [http.StreamedResponse] from the response data printed by the | 171 /// Returns a [http.StreamedResponse] from the response data printed by the |
| 164 /// `curl` [process]. [lines] are the headers that `curl` wrote to a file. | 172 /// `curl` [process]. [lines] are the headers that `curl` wrote to a file. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 /// path to the bundled `curl.exe`; elsewhere, this is just "curl", and we | 209 /// path to the bundled `curl.exe`; elsewhere, this is just "curl", and we |
| 202 /// assume it to be installed and on the user's PATH. | 210 /// assume it to be installed and on the user's PATH. |
| 203 static String get _defaultExecutable { | 211 static String get _defaultExecutable { |
| 204 if (Platform.operatingSystem != 'windows') return 'curl'; | 212 if (Platform.operatingSystem != 'windows') return 'curl'; |
| 205 // Note: This line of code gets munged by create_sdk.py to be the correct | 213 // Note: This line of code gets munged by create_sdk.py to be the correct |
| 206 // relative path to curl in the SDK. | 214 // relative path to curl in the SDK. |
| 207 var pathToCurl = "../../third_party/curl/curl.exe"; | 215 var pathToCurl = "../../third_party/curl/curl.exe"; |
| 208 return relativeToPub(pathToCurl); | 216 return relativeToPub(pathToCurl); |
| 209 } | 217 } |
| 210 } | 218 } |
| OLD | NEW |