Chromium Code Reviews| Index: sdk/lib/io/http_impl.dart |
| diff --git a/sdk/lib/io/http_impl.dart b/sdk/lib/io/http_impl.dart |
| index 9d6456f82076389b0905bf22f1b2abf8351df328..d95fb5b76a3a015e44d4c4c666ffc5b0512676c3 100644 |
| --- a/sdk/lib/io/http_impl.dart |
| +++ b/sdk/lib/io/http_impl.dart |
| @@ -1071,6 +1071,7 @@ class _HttpClientConnection { |
| StreamSubscription _subscription; |
| final _HttpClient _httpClient; |
| bool _dispose = false; |
| + bool closed = false; |
|
Søren Gjesse
2013/05/17 07:09:28
Private? (also key above).
Anders Johnsen
2013/05/17 08:27:59
This is used from another class (HttpClient). Also
|
| Completer<_HttpIncoming> _nextResponseCompleter; |
| Future _streamFuture; |
| @@ -1102,11 +1103,19 @@ class _HttpClientConnection { |
| } |
| }, |
| onDone: () { |
| + if (_nextResponseCompleter != null) { |
| + _nextResponseCompleter.completeError(new HttpException( |
| + "Connection closed before response was received")); |
| + _nextResponseCompleter = null; |
| + } |
| close(); |
| }); |
| } |
| _HttpClientRequest send(Uri uri, int port, String method, _Proxy proxy) { |
| + if (closed) { |
| + throw new HttpException("Socket closed before request was sent"); |
| + } |
| // Start with pausing the parser. |
| _subscription.pause(); |
| _ProxyCredentials proxyCreds; // Credentials used to authorize proxy. |
| @@ -1227,11 +1236,13 @@ class _HttpClientConnection { |
| } |
| void destroy() { |
| + closed = true; |
| _httpClient._connectionClosed(this); |
| _socket.destroy(); |
| } |
| void close() { |
| + closed = true; |
| _httpClient._connectionClosed(this); |
| _streamFuture |
| // TODO(ajohnsen): Add timeout. |
| @@ -1407,10 +1418,19 @@ class _HttpClient implements HttpClient { |
| } |
| return _getConnection(uri.domain, port, proxyConf, isSecure) |
| .then((info) { |
| - return info.connection.send(uri, |
| - port, |
| - method.toUpperCase(), |
| - info.proxy); |
| + send(info) { |
| + return info.connection.send(uri, |
| + port, |
| + method.toUpperCase(), |
| + info.proxy); |
| + } |
| + // If the connection was closed before the request was sent, create |
| + // and use another connection. |
| + if (info.connection.closed) { |
| + return _getConnection(uri.domain, port, proxyConf, isSecure) |
| + .then(send); |
| + } |
| + return send(info); |
| }); |
| } |