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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.addError); | 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 cancelOnError}) { |
129 return controller.stream.listen( | 129 return controller.stream.listen( |
130 onData, | 130 onData, |
131 onError: onError, | 131 onError: onError, |
132 onDone: onDone, | 132 onDone: onDone, |
133 unsubscribeOnError: unsubscribeOnError); | 133 cancelOnError: cancelOnError); |
134 } | 134 } |
135 | 135 |
136 void resume() { | 136 void resume() { |
137 paused = false; | 137 paused = false; |
138 if (carryOverData != null) { | 138 if (carryOverData != null) { |
139 var data = carryOverData; | 139 var data = carryOverData; |
140 carryOverData = null; | 140 carryOverData = null; |
141 controller.add(data); | 141 controller.add(data); |
142 // If the consumer pauses again after the carry-over data, we'll not | 142 // If the consumer pauses again after the carry-over data, we'll not |
143 // continue our subscriber until the next resume. | 143 // continue our subscriber until the next resume. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 _controller = new StreamController<_HttpIncoming>( | 211 _controller = new StreamController<_HttpIncoming>( |
212 onSubscriptionStateChange: _updateParsePauseState, | 212 onSubscriptionStateChange: _updateParsePauseState, |
213 onPauseStateChange: _updateParsePauseState); | 213 onPauseStateChange: _updateParsePauseState); |
214 _reset(); | 214 _reset(); |
215 } | 215 } |
216 | 216 |
217 | 217 |
218 StreamSubscription<_HttpIncoming> listen(void onData(_HttpIncoming event), | 218 StreamSubscription<_HttpIncoming> listen(void onData(_HttpIncoming event), |
219 {void onError(AsyncError error), | 219 {void onError(AsyncError error), |
220 void onDone(), | 220 void onDone(), |
221 bool unsubscribeOnError}) { | 221 bool cancelOnError}) { |
222 return _controller.stream.listen(onData, | 222 return _controller.stream.listen(onData, |
223 onError: onError, | 223 onError: onError, |
224 onDone: onDone, | 224 onDone: onDone, |
225 unsubscribeOnError: unsubscribeOnError); | 225 cancelOnError: cancelOnError); |
226 } | 226 } |
227 | 227 |
228 Future<_HttpParser> addStream(Stream<List<int>> stream) { | 228 Future<_HttpParser> addStream(Stream<List<int>> stream) { |
229 // Listen to the stream and handle data accordingly. When a | 229 // Listen to the stream and handle data accordingly. When a |
230 // _HttpIncoming is created, _dataPause, _dataResume, _dataDone is | 230 // _HttpIncoming is created, _dataPause, _dataResume, _dataDone is |
231 // given to provide a way of controlling the parser. | 231 // given to provide a way of controlling the parser. |
232 // TODO(ajohnsen): Remove _dataPause, _dataResume and _dataDone and clean up | 232 // TODO(ajohnsen): Remove _dataPause, _dataResume and _dataDone and clean up |
233 // how the _HttpIncoming signals the parser. | 233 // how the _HttpIncoming signals the parser. |
234 var completer = new Completer(); | 234 var completer = new Completer(); |
235 _socketSubscription = stream.listen( | 235 _socketSubscription = stream.listen( |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 StreamController<_HttpIncoming> _controller; | 975 StreamController<_HttpIncoming> _controller; |
976 StreamController<List<int>> _bodyController; | 976 StreamController<List<int>> _bodyController; |
977 } | 977 } |
978 | 978 |
979 | 979 |
980 class HttpParserException implements Exception { | 980 class HttpParserException implements Exception { |
981 const HttpParserException([String this.message = ""]); | 981 const HttpParserException([String this.message = ""]); |
982 String toString() => "HttpParserException: $message"; | 982 String toString() => "HttpParserException: $message"; |
983 final String message; | 983 final String message; |
984 } | 984 } |
OLD | NEW |