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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 if (subscription == null) { | 111 if (subscription == null) { |
112 // Socket was already closed. | 112 // Socket was already closed. |
113 if (carryOverData != null) controller.add(carryOverData); | 113 if (carryOverData != null) controller.add(carryOverData); |
114 controller.close(); | 114 controller.close(); |
115 } else { | 115 } else { |
116 pause(); | 116 pause(); |
117 if (oldResumeCompleter != null) oldResumeCompleter.complete(); | 117 if (oldResumeCompleter != null) oldResumeCompleter.complete(); |
118 subscription.resume(); | 118 subscription.resume(); |
119 subscription.onData(controller.add); | 119 subscription.onData(controller.add); |
120 subscription.onDone(controller.close); | 120 subscription.onDone(controller.close); |
121 subscription.onError(controller.signalError); | 121 subscription.onError(controller.addError); |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 StreamSubscription<List<int>> listen(void onData(List<int> event), | 125 StreamSubscription<List<int>> listen(void onData(List<int> event), |
126 {void onError(AsyncError error), | 126 {void onError(AsyncError error), |
127 void onDone(), | 127 void onDone(), |
128 bool unsubscribeOnError}) { | 128 bool unsubscribeOnError}) { |
129 return controller.stream.listen( | 129 return controller.stream.listen( |
130 onData, | 130 onData, |
131 onError: onError, | 131 onError: onError, |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 | 701 |
702 void _onDone() { | 702 void _onDone() { |
703 // onDone cancles the subscription. | 703 // onDone cancles the subscription. |
704 _socketSubscription = null; | 704 _socketSubscription = null; |
705 if (_state == _State.CLOSED || _state == _State.FAILURE) return; | 705 if (_state == _State.CLOSED || _state == _State.FAILURE) return; |
706 | 706 |
707 if (_incoming != null) { | 707 if (_incoming != null) { |
708 if (_state != _State.UPGRADED && | 708 if (_state != _State.UPGRADED && |
709 !(_state == _State.START && !_requestParser) && | 709 !(_state == _State.START && !_requestParser) && |
710 !(_state == _State.BODY && !_chunked && _transferLength == -1)) { | 710 !(_state == _State.BODY && !_chunked && _transferLength == -1)) { |
711 _bodyController.signalError( | 711 _bodyController.addError( |
712 new AsyncError( | 712 new AsyncError( |
713 new HttpParserException( | 713 new HttpParserException( |
714 "Connection closed while receiving data"))); | 714 "Connection closed while receiving data"))); |
715 } | 715 } |
716 _closeIncoming(); | 716 _closeIncoming(); |
717 _controller.close(); | 717 _controller.close(); |
718 return; | 718 return; |
719 } | 719 } |
720 // If the connection is idle the HTTP stream is closed. | 720 // If the connection is idle the HTTP stream is closed. |
721 if (_state == _State.START) { | 721 if (_state == _State.START) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 // throw the error. | 754 // throw the error. |
755 error( | 755 error( |
756 new AsyncError( | 756 new AsyncError( |
757 new HttpParserException( | 757 new HttpParserException( |
758 "Connection closed before full body was received"))); | 758 "Connection closed before full body was received"))); |
759 } | 759 } |
760 _controller.close(); | 760 _controller.close(); |
761 } | 761 } |
762 | 762 |
763 void _onError(e) { | 763 void _onError(e) { |
764 _controller.signalError(e); | 764 _controller.addError(e); |
765 } | 765 } |
766 | 766 |
767 String get version { | 767 String get version { |
768 switch (_httpVersion) { | 768 switch (_httpVersion) { |
769 case _HttpVersion.HTTP10: | 769 case _HttpVersion.HTTP10: |
770 return "1.0"; | 770 return "1.0"; |
771 case _HttpVersion.HTTP11: | 771 case _HttpVersion.HTTP11: |
772 return "1.1"; | 772 return "1.1"; |
773 } | 773 } |
774 return null; | 774 return null; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 _continueParsing(); | 922 _continueParsing(); |
923 } else { | 923 } else { |
924 _pauseParsing(); | 924 _pauseParsing(); |
925 } | 925 } |
926 } | 926 } |
927 } | 927 } |
928 | 928 |
929 void error(error) { | 929 void error(error) { |
930 if (_socketSubscription != null) _socketSubscription.cancel(); | 930 if (_socketSubscription != null) _socketSubscription.cancel(); |
931 _state = _State.FAILURE; | 931 _state = _State.FAILURE; |
932 _controller.signalError(error); | 932 _controller.addError(error); |
933 _controller.close(); | 933 _controller.close(); |
934 } | 934 } |
935 | 935 |
936 // State. | 936 // State. |
937 bool _parserCalled = false; | 937 bool _parserCalled = false; |
938 | 938 |
939 // The data that is currently being parsed. | 939 // The data that is currently being parsed. |
940 List<int> _buffer; | 940 List<int> _buffer; |
941 int _index; | 941 int _index; |
942 | 942 |
(...skipping 27 matching lines...) Expand all Loading... |
970 StreamController<_HttpIncoming> _controller; | 970 StreamController<_HttpIncoming> _controller; |
971 StreamController<List<int>> _bodyController; | 971 StreamController<List<int>> _bodyController; |
972 } | 972 } |
973 | 973 |
974 | 974 |
975 class HttpParserException implements Exception { | 975 class HttpParserException implements Exception { |
976 const HttpParserException([String this.message = ""]); | 976 const HttpParserException([String this.message = ""]); |
977 String toString() => "HttpParserException: $message"; | 977 String toString() => "HttpParserException: $message"; |
978 final String message; | 978 final String message; |
979 } | 979 } |
OLD | NEW |