| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 Future<_HttpParser> close() { | 249 Future<_HttpParser> close() { |
| 250 _onDone(); | 250 _onDone(); |
| 251 return new Future.value(this); | 251 return new Future.value(this); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void _parse() { | 254 void _parse() { |
| 255 try { | 255 try { |
| 256 _doParse(); | 256 _doParse(); |
| 257 } catch (e, s) { | 257 } catch (e, s) { |
| 258 _state = _State.FAILURE; | 258 _state = _State.FAILURE; |
| 259 error(e, s); | 259 _reportError(e, s); |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 | 262 |
| 263 // From RFC 2616. | 263 // From RFC 2616. |
| 264 // generic-message = start-line | 264 // generic-message = start-line |
| 265 // *(message-header CRLF) | 265 // *(message-header CRLF) |
| 266 // CRLF | 266 // CRLF |
| 267 // [ message-body ] | 267 // [ message-body ] |
| 268 // start-line = Request-Line | Status-Line | 268 // start-line = Request-Line | Status-Line |
| 269 // Request-Line = Method SP Request-URI SP HTTP-Version CRLF | 269 // Request-Line = Method SP Request-URI SP HTTP-Version CRLF |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 _bodyController.addError( | 730 _bodyController.addError( |
| 731 new HttpException("Connection closed while receiving data")); | 731 new HttpException("Connection closed while receiving data")); |
| 732 } | 732 } |
| 733 _closeIncoming(true); | 733 _closeIncoming(true); |
| 734 _controller.close(); | 734 _controller.close(); |
| 735 return; | 735 return; |
| 736 } | 736 } |
| 737 // If the connection is idle the HTTP stream is closed. | 737 // If the connection is idle the HTTP stream is closed. |
| 738 if (_state == _State.START) { | 738 if (_state == _State.START) { |
| 739 if (!_requestParser) { | 739 if (!_requestParser) { |
| 740 error(new HttpException( | 740 _reportError(new HttpException( |
| 741 "Connection closed before full header was received")); | 741 "Connection closed before full header was received")); |
| 742 } | 742 } |
| 743 _controller.close(); | 743 _controller.close(); |
| 744 return; | 744 return; |
| 745 } | 745 } |
| 746 | 746 |
| 747 if (_state == _State.UPGRADED) { | 747 if (_state == _State.UPGRADED) { |
| 748 _controller.close(); | 748 _controller.close(); |
| 749 return; | 749 return; |
| 750 } | 750 } |
| 751 | 751 |
| 752 if (_state < _State.FIRST_BODY_STATE) { | 752 if (_state < _State.FIRST_BODY_STATE) { |
| 753 _state = _State.FAILURE; | 753 _state = _State.FAILURE; |
| 754 // Report the error through the error callback if any. Otherwise | 754 // Report the error through the error callback if any. Otherwise |
| 755 // throw the error. | 755 // throw the error. |
| 756 error(new HttpException( | 756 _reportError(new HttpException( |
| 757 "Connection closed before full header was received")); | 757 "Connection closed before full header was received")); |
| 758 _controller.close(); | 758 _controller.close(); |
| 759 return; | 759 return; |
| 760 } | 760 } |
| 761 | 761 |
| 762 if (!_chunked && _transferLength == -1) { | 762 if (!_chunked && _transferLength == -1) { |
| 763 _state = _State.CLOSED; | 763 _state = _State.CLOSED; |
| 764 } else { | 764 } else { |
| 765 _state = _State.FAILURE; | 765 _state = _State.FAILURE; |
| 766 // Report the error through the error callback if any. Otherwise | 766 // Report the error through the error callback if any. Otherwise |
| 767 // throw the error. | 767 // throw the error. |
| 768 error(new HttpException( | 768 _reportError(new HttpException( |
| 769 "Connection closed before full body was received")); | 769 "Connection closed before full body was received")); |
| 770 } | 770 } |
| 771 _controller.close(); | 771 _controller.close(); |
| 772 } | 772 } |
| 773 | 773 |
| 774 void _onError(e) { | 774 void _onError(e) { |
| 775 _controller.addError(e); | 775 _controller.addError(e); |
| 776 } | 776 } |
| 777 | 777 |
| 778 String get version { | 778 String get version { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 if (!_bodyPaused && !_parserCalled) { | 938 if (!_bodyPaused && !_parserCalled) { |
| 939 _parse(); | 939 _parse(); |
| 940 } | 940 } |
| 941 } else { | 941 } else { |
| 942 if (!_paused && !_parserCalled) { | 942 if (!_paused && !_parserCalled) { |
| 943 _parse(); | 943 _parse(); |
| 944 } | 944 } |
| 945 } | 945 } |
| 946 } | 946 } |
| 947 | 947 |
| 948 void error(error, [stackTrace]) { | 948 void _reportError(error, [stackTrace]) { |
| 949 if (_socketSubscription != null) _socketSubscription.cancel(); | 949 if (_socketSubscription != null) _socketSubscription.cancel(); |
| 950 _state = _State.FAILURE; | 950 _state = _State.FAILURE; |
| 951 _controller.addError(error, stackTrace); | 951 _controller.addError(error, stackTrace); |
| 952 _controller.close(); | 952 _controller.close(); |
| 953 } | 953 } |
| 954 | 954 |
| 955 // State. | 955 // State. |
| 956 bool _parserCalled = false; | 956 bool _parserCalled = false; |
| 957 | 957 |
| 958 // The data that is currently being parsed. | 958 // The data that is currently being parsed. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 982 _HttpHeaders _headers; | 982 _HttpHeaders _headers; |
| 983 | 983 |
| 984 // The current incoming connection. | 984 // The current incoming connection. |
| 985 _HttpIncoming _incoming; | 985 _HttpIncoming _incoming; |
| 986 StreamSubscription _socketSubscription; | 986 StreamSubscription _socketSubscription; |
| 987 bool _paused = true; | 987 bool _paused = true; |
| 988 bool _bodyPaused = false; | 988 bool _bodyPaused = false; |
| 989 StreamController<_HttpIncoming> _controller; | 989 StreamController<_HttpIncoming> _controller; |
| 990 StreamController<List<int>> _bodyController; | 990 StreamController<List<int>> _bodyController; |
| 991 } | 991 } |
| OLD | NEW |