Don't die because we write empty arrays to cURL.

Review URL: https://codereview.chromium.org//11821062

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16941 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
nweiz@google.com 2013-01-10 23:21:41 +00:00
parent ba1f89e2b0
commit 9c8eb660d5
2 changed files with 12 additions and 2 deletions

View file

@ -38,7 +38,6 @@ class CurlClient extends http.BaseClient {
return withTempDir((tempDir) {
var headerFile = join(tempDir, "curl-headers");
var arguments = _argumentsForRequest(request, headerFile);
log.process(executable, arguments);
var process;
return startProcess(executable, arguments).then((process_) {
process = process_;

View file

@ -599,7 +599,18 @@ class _OutputStreamConsumer implements StreamConsumer<List<int>, dynamic> {
// the following TODO.
var completed = false;
var completer = new Completer();
stream.listen((data) => _outputStream.write(data), onDone: () {
stream.listen((data) {
// Writing empty data to a closed stream can cause errors.
if (data.isEmpty) return;
// TODO(nweiz): remove this try/catch when issue 7836 is fixed.
try {
_outputStream.write(data);
} catch (e, stack) {
if (!completed) completer.completeError(e, stack);
completed = true;
}
}, onDone: () {
_outputStream.close();
// TODO(nweiz): wait until _outputStream.onClosed is called once issue
// 7761 is fixed.