| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Global constants. | 7 // Global constants. |
| 8 class _Const { | 8 class _Const { |
| 9 // Bytes for "HTTP". | 9 // Bytes for "HTTP". |
| 10 static const HTTP = const [72, 84, 84, 80]; | 10 static const HTTP = const [72, 84, 84, 80]; |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 if (_state == _State.CLOSED || _state == _State.FAILURE) return; | 722 if (_state == _State.CLOSED || _state == _State.FAILURE) return; |
| 723 | 723 |
| 724 if (_incoming != null) { | 724 if (_incoming != null) { |
| 725 if (_state != _State.UPGRADED && | 725 if (_state != _State.UPGRADED && |
| 726 !(_state == _State.START && !_requestParser) && | 726 !(_state == _State.START && !_requestParser) && |
| 727 !(_state == _State.BODY && !_chunked && _transferLength == -1)) { | 727 !(_state == _State.BODY && !_chunked && _transferLength == -1)) { |
| 728 _bodyController.addError( | 728 _bodyController.addError( |
| 729 new HttpParserException( | 729 new HttpParserException( |
| 730 "Connection closed while receiving data")); | 730 "Connection closed while receiving data")); |
| 731 } | 731 } |
| 732 _closeIncoming(); | 732 _closeIncoming(true); |
| 733 _controller.close(); | 733 _controller.close(); |
| 734 return; | 734 return; |
| 735 } | 735 } |
| 736 // If the connection is idle the HTTP stream is closed. | 736 // If the connection is idle the HTTP stream is closed. |
| 737 if (_state == _State.START) { | 737 if (_state == _State.START) { |
| 738 if (!_requestParser) { | 738 if (!_requestParser) { |
| 739 error(new HttpParserException( | 739 error(new HttpParserException( |
| 740 "Connection closed before full header was received")); | 740 "Connection closed before full header was received")); |
| 741 } | 741 } |
| 742 _controller.close(); | 742 _controller.close(); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 if (incoming != _incoming) return; | 902 if (incoming != _incoming) return; |
| 903 assert(_bodyPaused); | 903 assert(_bodyPaused); |
| 904 _bodyPaused = false; | 904 _bodyPaused = false; |
| 905 _pauseStateChanged(); | 905 _pauseStateChanged(); |
| 906 }, | 906 }, |
| 907 onCancel: () { | 907 onCancel: () { |
| 908 if (incoming != _incoming) return; | 908 if (incoming != _incoming) return; |
| 909 if (_socketSubscription != null) { | 909 if (_socketSubscription != null) { |
| 910 _socketSubscription.cancel(); | 910 _socketSubscription.cancel(); |
| 911 } | 911 } |
| 912 _closeIncoming(); | 912 _closeIncoming(true); |
| 913 _controller.close(); | 913 _controller.close(); |
| 914 }); | 914 }); |
| 915 incoming = _incoming = new _HttpIncoming( | 915 incoming = _incoming = new _HttpIncoming( |
| 916 _headers, transferLength, _bodyController.stream); | 916 _headers, transferLength, _bodyController.stream); |
| 917 _bodyPaused = true; | 917 _bodyPaused = true; |
| 918 _pauseStateChanged(); | 918 _pauseStateChanged(); |
| 919 } | 919 } |
| 920 | 920 |
| 921 void _closeIncoming() { | 921 void _closeIncoming([bool closing = false]) { |
| 922 // Ignore multiple close (can happend in re-entrance). | 922 // Ignore multiple close (can happend in re-entrance). |
| 923 if (_incoming == null) return; | 923 if (_incoming == null) return; |
| 924 var tmp = _incoming; | 924 var tmp = _incoming; |
| 925 tmp.close(); | 925 tmp.close(closing); |
| 926 _incoming = null; | 926 _incoming = null; |
| 927 if (_bodyController != null) { | 927 if (_bodyController != null) { |
| 928 _bodyController.close(); | 928 _bodyController.close(); |
| 929 _bodyController = null; | 929 _bodyController = null; |
| 930 } | 930 } |
| 931 _bodyPaused = false; | 931 _bodyPaused = false; |
| 932 _pauseStateChanged(); | 932 _pauseStateChanged(); |
| 933 } | 933 } |
| 934 | 934 |
| 935 void _pauseStateChanged() { | 935 void _pauseStateChanged() { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 StreamController<_HttpIncoming> _controller; | 997 StreamController<_HttpIncoming> _controller; |
| 998 StreamController<List<int>> _bodyController; | 998 StreamController<List<int>> _bodyController; |
| 999 } | 999 } |
| 1000 | 1000 |
| 1001 | 1001 |
| 1002 class HttpParserException implements Exception { | 1002 class HttpParserException implements Exception { |
| 1003 const HttpParserException([String this.message = ""]); | 1003 const HttpParserException([String this.message = ""]); |
| 1004 String toString() => "HttpParserException: $message"; | 1004 String toString() => "HttpParserException: $message"; |
| 1005 final String message; | 1005 final String message; |
| 1006 } | 1006 } |
| OLD | NEW |