| 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 // The close queue handles graceful closing of HTTP connections. When | 5 // The close queue handles graceful closing of HTTP connections. When |
| 6 // a connection is added to the queue it will enter a wait state | 6 // a connection is added to the queue it will enter a wait state |
| 7 // waiting for all data written and possibly socket shutdown from | 7 // waiting for all data written and possibly socket shutdown from |
| 8 // peer. | 8 // peer. |
| 9 class _CloseQueue { | 9 class _CloseQueue { |
| 10 _CloseQueue() : _q = new Set<_HttpConnectionBase>(); | 10 _CloseQueue() : _q = new Set<_HttpConnectionBase>(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // the queue. | 25 // the queue. |
| 26 if (connection._isFullyClosed) { | 26 if (connection._isFullyClosed) { |
| 27 connection._socket.close(); | 27 connection._socket.close(); |
| 28 if (connection.onClosed != null) connection.onClosed(); | 28 if (connection.onClosed != null) connection.onClosed(); |
| 29 return; | 29 return; |
| 30 } | 30 } |
| 31 | 31 |
| 32 connection._state |= _HttpConnectionBase.CLOSING; | 32 connection._state |= _HttpConnectionBase.CLOSING; |
| 33 _q.add(connection); | 33 _q.add(connection); |
| 34 | 34 |
| 35 // If output stream is not closed for writing close it now and | 35 // If the output stream is not closed for writing, close it now and |
| 36 // wait for callback when closed. | 36 // wait for callback when closed. |
| 37 if (!connection._isWriteClosed) { | 37 if (!connection._isWriteClosed) { |
| 38 connection._socket.outputStream.close(); | 38 connection._socket.outputStream.close(); |
| 39 connection._socket.outputStream.onClosed = () { | 39 connection._socket.outputStream.onClosed = () { |
| 40 connection._state |= _HttpConnectionBase.WRITE_CLOSED; | 40 connection._state |= _HttpConnectionBase.WRITE_CLOSED; |
| 41 closeIfDone(); | 41 closeIfDone(); |
| 42 }; | 42 }; |
| 43 } else { | 43 } else { |
| 44 connection._socket.outputStream.onClosed = () { assert(false); }; | 44 connection._socket.outputStream.onClosed = () { assert(false); }; |
| 45 } | 45 } |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 // If we are done writing the response, and the connection is | 931 // If we are done writing the response, and the connection is |
| 932 // not persistent, we must close. Also if using HTTP 1.0 and the | 932 // not persistent, we must close. Also if using HTTP 1.0 and the |
| 933 // content length was not known we must close to indicate end of | 933 // content length was not known we must close to indicate end of |
| 934 // body. | 934 // body. |
| 935 bool close = | 935 bool close = |
| 936 !_response.persistentConnection || | 936 !_response.persistentConnection || |
| 937 (_response._protocolVersion == "1.0" && _response._contentLength < 0); | 937 (_response._protocolVersion == "1.0" && _response._contentLength < 0); |
| 938 _request = null; | 938 _request = null; |
| 939 _response = null; | 939 _response = null; |
| 940 if (close) { | 940 if (close) { |
| 941 _httpParser.cancel(); |
| 941 _server._closeQueue.add(this); | 942 _server._closeQueue.add(this); |
| 942 } else { | 943 } else { |
| 943 _state = _HttpConnectionBase.IDLE; | 944 _state = _HttpConnectionBase.IDLE; |
| 944 } | 945 } |
| 945 } else if (_isResponseDone && _hasBody) { | 946 } else if (_isResponseDone && _hasBody) { |
| 946 // If the response is closed before the request is fully read | 947 // If the response is closed before the request is fully read |
| 947 // close this connection. If there is buffered output | 948 // close this connection. If there is buffered output |
| 948 // (e.g. error response for invalid request where the server did | 949 // (e.g. error response for invalid request where the server did |
| 949 // not care to read the request body) this is send. | 950 // not care to read the request body) this is send. |
| 950 assert(!_isRequestDone); | 951 assert(!_isRequestDone); |
| 951 _writeBufferedResponse(); | 952 _writeBufferedResponse(); |
| 952 _close(); | 953 _httpParser.cancel(); |
| 953 _server._closeQueue.add(this); | 954 _server._closeQueue.add(this); |
| 954 } | 955 } |
| 955 } | 956 } |
| 956 | 957 |
| 957 void _onDataEnd(bool close) { | 958 void _onDataEnd(bool close) { |
| 958 // Start sending queued response if any. | 959 // Start sending queued response if any. |
| 959 _state |= _HttpConnectionBase.REQUEST_DONE; | 960 _state |= _HttpConnectionBase.REQUEST_DONE; |
| 960 _writeBufferedResponse(); | 961 _writeBufferedResponse(); |
| 961 _request._onDataEnd(); | 962 _request._onDataEnd(); |
| 962 _checkDone(); | 963 _checkDone(); |
| (...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2324 | 2325 |
| 2325 | 2326 |
| 2326 class _RedirectInfo implements RedirectInfo { | 2327 class _RedirectInfo implements RedirectInfo { |
| 2327 const _RedirectInfo(int this.statusCode, | 2328 const _RedirectInfo(int this.statusCode, |
| 2328 String this.method, | 2329 String this.method, |
| 2329 Uri this.location); | 2330 Uri this.location); |
| 2330 final int statusCode; | 2331 final int statusCode; |
| 2331 final String method; | 2332 final String method; |
| 2332 final Uri location; | 2333 final Uri location; |
| 2333 } | 2334 } |
| OLD | NEW |