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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 } else { | 119 } else { |
120 pause(); | 120 pause(); |
121 subscription.resume(); | 121 subscription.resume(); |
122 subscription.onData(controller.add); | 122 subscription.onData(controller.add); |
123 subscription.onDone(controller.close); | 123 subscription.onDone(controller.close); |
124 subscription.onError(controller.addError); | 124 subscription.onError(controller.addError); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 StreamSubscription<List<int>> listen(void onData(List<int> event), | 128 StreamSubscription<List<int>> listen(void onData(List<int> event), |
129 {void onError(error), | 129 {Function onError, |
130 void onDone(), | 130 void onDone(), |
131 bool cancelOnError}) { | 131 bool cancelOnError}) { |
132 return controller.stream.listen( | 132 return controller.stream.listen( |
133 onData, | 133 onData, |
134 onError: onError, | 134 onError: onError, |
135 onDone: onDone, | 135 onDone: onDone, |
136 cancelOnError: cancelOnError); | 136 cancelOnError: cancelOnError); |
137 } | 137 } |
138 | 138 |
139 void resume() { | 139 void resume() { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 try { | 213 try { |
214 _socketSubscription.cancel(); | 214 _socketSubscription.cancel(); |
215 } catch (e) { | 215 } catch (e) { |
216 } | 216 } |
217 }); | 217 }); |
218 _reset(); | 218 _reset(); |
219 } | 219 } |
220 | 220 |
221 | 221 |
222 StreamSubscription<_HttpIncoming> listen(void onData(_HttpIncoming event), | 222 StreamSubscription<_HttpIncoming> listen(void onData(_HttpIncoming event), |
223 {void onError(error), | 223 {Function onError, |
224 void onDone(), | 224 void onDone(), |
225 bool cancelOnError}) { | 225 bool cancelOnError}) { |
226 return _controller.stream.listen(onData, | 226 return _controller.stream.listen(onData, |
227 onError: onError, | 227 onError: onError, |
228 onDone: onDone, | 228 onDone: onDone, |
229 cancelOnError: cancelOnError); | 229 cancelOnError: cancelOnError); |
230 } | 230 } |
231 | 231 |
232 Future<_HttpParser> addStream(Stream<List<int>> stream) { | 232 Future<_HttpParser> addStream(Stream<List<int>> stream) { |
233 // Listen to the stream and handle data accordingly. When a | 233 // Listen to the stream and handle data accordingly. When a |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 error(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, [StackTrace stackTrace]) { |
775 _controller.addError(e); | 775 _controller.addError(e, stackTrace); |
776 } | 776 } |
777 | 777 |
778 String get version { | 778 String get version { |
779 switch (_httpVersion) { | 779 switch (_httpVersion) { |
780 case _HttpVersion.HTTP10: | 780 case _HttpVersion.HTTP10: |
781 return "1.0"; | 781 return "1.0"; |
782 case _HttpVersion.HTTP11: | 782 case _HttpVersion.HTTP11: |
783 return "1.1"; | 783 return "1.1"; |
784 } | 784 } |
785 return null; | 785 return null; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |