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 17 matching lines...) Expand all Loading... |
28 CurlClient([String executable]) | 28 CurlClient([String executable]) |
29 : executable = executable == null ? _defaultExecutable : executable; | 29 : executable = executable == null ? _defaultExecutable : executable; |
30 | 30 |
31 /// Sends a request via `curl` and returns the response. | 31 /// Sends a request via `curl` and returns the response. |
32 Future<http.StreamedResponse> send(http.BaseRequest request) { | 32 Future<http.StreamedResponse> send(http.BaseRequest request) { |
33 var requestStream = request.finalize(); | 33 var requestStream = request.finalize(); |
34 return withTempDir((tempDir) { | 34 return withTempDir((tempDir) { |
35 var headerFile = new Path(tempDir).append("curl-headers").toNativePath(); | 35 var headerFile = new Path(tempDir).append("curl-headers").toNativePath(); |
36 var arguments = _argumentsForRequest(request, headerFile); | 36 var arguments = _argumentsForRequest(request, headerFile); |
37 var process; | 37 var process; |
38 return Process.start(executable, arguments).chain((process_) { | 38 return startProcess(executable, arguments).chain((process_) { |
39 process = process_; | 39 process = process_; |
40 if (requestStream.closed) { | 40 if (requestStream.closed) { |
41 process.stdin.close(); | 41 process.stdin.close(); |
42 } else { | 42 } else { |
43 requestStream.pipe(process.stdin); | 43 requestStream.pipe(process.stdin); |
44 } | 44 } |
45 | 45 |
46 return _waitForHeaders(process, expectBody: request.method != "HEAD"); | 46 return _waitForHeaders(process, expectBody: request.method != "HEAD"); |
47 }).chain((_) => new File(headerFile).readAsLines()) | 47 }).chain((_) => new File(headerFile).readAsLines()) |
48 .transform((lines) => _buildResponse(request, process, lines)); | 48 .transform((lines) => _buildResponse(request, process, lines)); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 /// path to the bundled `curl.exe`; elsewhere, this is just "curl", and we | 186 /// path to the bundled `curl.exe`; elsewhere, this is just "curl", and we |
187 /// assume it to be installed and on the user's PATH. | 187 /// assume it to be installed and on the user's PATH. |
188 static String get _defaultExecutable { | 188 static String get _defaultExecutable { |
189 if (Platform.operatingSystem != 'windows') return 'curl'; | 189 if (Platform.operatingSystem != 'windows') return 'curl'; |
190 // Note: This line of code gets munged by create_sdk.py to be the correct | 190 // Note: This line of code gets munged by create_sdk.py to be the correct |
191 // relative path to curl in the SDK. | 191 // relative path to curl in the SDK. |
192 var pathToCurl = "../../third_party/curl/curl.exe"; | 192 var pathToCurl = "../../third_party/curl/curl.exe"; |
193 return relativeToPub(pathToCurl); | 193 return relativeToPub(pathToCurl); |
194 } | 194 } |
195 } | 195 } |
OLD | NEW |