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 /** | 5 /** |
6 * Helper functionality to make working with IO easier. | 6 * Helper functionality to make working with IO easier. |
7 */ | 7 */ |
8 library io; | 8 library io; |
9 | 9 |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 } | 659 } |
660 | 660 |
661 if (environment != null) { | 661 if (environment != null) { |
662 options.environment = new Map.from(Platform.environment); | 662 options.environment = new Map.from(Platform.environment); |
663 environment.forEach((key, value) => options.environment[key] = value); | 663 environment.forEach((key, value) => options.environment[key] = value); |
664 } | 664 } |
665 | 665 |
666 return fn(executable, args, options); | 666 return fn(executable, args, options); |
667 } | 667 } |
668 | 668 |
| 669 /// Closes [response] while ignoring the body of [request]. Returns a Future |
| 670 /// that completes once the response is closed. |
| 671 /// |
| 672 /// Due to issue 6984, it's necessary to drain the request body before closing |
| 673 /// the response. |
| 674 Future closeHttpResponse(HttpRequest request, HttpResponse response) { |
| 675 // TODO(nweiz): remove this when issue 4061 is fixed. |
| 676 var stackTrace; |
| 677 try { |
| 678 throw ""; |
| 679 } catch (_, localStackTrace) { |
| 680 stackTrace = localStackTrace; |
| 681 } |
| 682 |
| 683 var completer = new Completer(); |
| 684 request.inputStream.onError = (e) => |
| 685 completer.completeException(e, stackTrace); |
| 686 request.inputStream.onData = request.inputStream.read; |
| 687 request.inputStream.onClosed = () { |
| 688 response.outputStream.close(); |
| 689 completer.complete(null); |
| 690 }; |
| 691 return completer.future; |
| 692 } |
| 693 |
669 /** | 694 /** |
670 * Wraps [input] to provide a timeout. If [input] completes before | 695 * Wraps [input] to provide a timeout. If [input] completes before |
671 * [milliseconds] have passed, then the return value completes in the same way. | 696 * [milliseconds] have passed, then the return value completes in the same way. |
672 * However, if [milliseconds] pass before [input] has completed, it completes | 697 * However, if [milliseconds] pass before [input] has completed, it completes |
673 * with a [TimeoutException] with [description] (which should be a fragment | 698 * with a [TimeoutException] with [description] (which should be a fragment |
674 * describing the action that timed out). | 699 * describing the action that timed out). |
675 * | 700 * |
676 * Note that timing out will not cancel the asynchronous operation behind | 701 * Note that timing out will not cancel the asynchronous operation behind |
677 * [input]. | 702 * [input]. |
678 */ | 703 */ |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 return new Directory(entry); | 1019 return new Directory(entry); |
995 } | 1020 } |
996 | 1021 |
997 /** | 1022 /** |
998 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 1023 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
999 */ | 1024 */ |
1000 Uri _getUri(uri) { | 1025 Uri _getUri(uri) { |
1001 if (uri is Uri) return uri; | 1026 if (uri is Uri) return uri; |
1002 return new Uri.fromString(uri); | 1027 return new Uri.fromString(uri); |
1003 } | 1028 } |
OLD | NEW |