| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 _subscription.resume(); | 176 _subscription.resume(); |
| 177 if (_userOnData != null) { | 177 if (_userOnData != null) { |
| 178 _userOnData(data); | 178 _userOnData(data); |
| 179 } | 179 } |
| 180 }); | 180 }); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 | 184 |
| 185 class _HttpDetachedIncoming extends Stream<List<int>> { | 185 class _HttpDetachedIncoming extends Stream<List<int>> { |
| 186 final StreamSubscription<List<int>> subscription; | 186 final StreamSubscription subscription; |
| 187 final List<int> bufferedData; | 187 final List<int> bufferedData; |
| 188 | 188 |
| 189 _HttpDetachedIncoming(this.subscription, this.bufferedData); | 189 _HttpDetachedIncoming(this.subscription, this.bufferedData); |
| 190 | 190 |
| 191 StreamSubscription<List<int>> listen(void onData(List<int> event), | 191 StreamSubscription<List<int>> listen(void onData(List<int> event), |
| 192 {Function onError, | 192 {Function onError, |
| 193 void onDone(), | 193 void onDone(), |
| 194 bool cancelOnError}) { | 194 bool cancelOnError}) { |
| 195 if (subscription != null) { | 195 if (subscription != null) { |
| 196 subscription | 196 subscription |
| 197 ..onData(onData) | 197 ..onData(onData) |
| 198 ..onError(onError) | 198 ..onError(onError) |
| 199 ..onDone(onDone); | 199 ..onDone(onDone); |
| 200 if (bufferedData == null) { | 200 if (bufferedData == null) { |
| 201 return subscription..resume(); | 201 return subscription..resume(); |
| 202 } | 202 } |
| 203 return new _HttpDetachedStreamSubscription(subscription, | 203 return new _HttpDetachedStreamSubscription(subscription, |
| 204 bufferedData, | 204 bufferedData, |
| 205 onData) | 205 onData) |
| 206 ..resume(); | 206 ..resume(); |
| 207 } else { | 207 } else { |
| 208 // TODO(26379): add test for this branch. | 208 return new Stream.fromIterable(bufferedData) |
| 209 return new Stream<List<int>>.fromIterable([bufferedData]) | |
| 210 .listen(onData, | 209 .listen(onData, |
| 211 onError: onError, | 210 onError: onError, |
| 212 onDone: onDone, | 211 onDone: onDone, |
| 213 cancelOnError: cancelOnError); | 212 cancelOnError: cancelOnError); |
| 214 } | 213 } |
| 215 } | 214 } |
| 216 } | 215 } |
| 217 | 216 |
| 218 | 217 |
| 219 /** | 218 /** |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 bool _connectionUpgrade; | 260 bool _connectionUpgrade; |
| 262 bool _chunked; | 261 bool _chunked; |
| 263 | 262 |
| 264 bool _noMessageBody = false; | 263 bool _noMessageBody = false; |
| 265 int _remainingContent = -1; | 264 int _remainingContent = -1; |
| 266 | 265 |
| 267 _HttpHeaders _headers; | 266 _HttpHeaders _headers; |
| 268 | 267 |
| 269 // The current incoming connection. | 268 // The current incoming connection. |
| 270 _HttpIncoming _incoming; | 269 _HttpIncoming _incoming; |
| 271 StreamSubscription<List<int>> _socketSubscription; | 270 StreamSubscription _socketSubscription; |
| 272 bool _paused = true; | 271 bool _paused = true; |
| 273 bool _bodyPaused = false; | 272 bool _bodyPaused = false; |
| 274 StreamController<_HttpIncoming> _controller; | 273 StreamController<_HttpIncoming> _controller; |
| 275 StreamController<List<int>> _bodyController; | 274 StreamController<List<int>> _bodyController; |
| 276 | 275 |
| 277 factory _HttpParser.requestParser() { | 276 factory _HttpParser.requestParser() { |
| 278 return new _HttpParser._(true); | 277 return new _HttpParser._(true); |
| 279 } | 278 } |
| 280 | 279 |
| 281 factory _HttpParser.responseParser() { | 280 factory _HttpParser.responseParser() { |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 } | 1063 } |
| 1065 } | 1064 } |
| 1066 | 1065 |
| 1067 void _reportError(error, [stackTrace]) { | 1066 void _reportError(error, [stackTrace]) { |
| 1068 if (_socketSubscription != null) _socketSubscription.cancel(); | 1067 if (_socketSubscription != null) _socketSubscription.cancel(); |
| 1069 _state = _State.FAILURE; | 1068 _state = _State.FAILURE; |
| 1070 _controller.addError(error, stackTrace); | 1069 _controller.addError(error, stackTrace); |
| 1071 _controller.close(); | 1070 _controller.close(); |
| 1072 } | 1071 } |
| 1073 } | 1072 } |
| OLD | NEW |