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