| 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 unsubscribeOnError}) { |
| 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 unsubscribeOnError: unsubscribeOnError); |
| 226 } | 226 } |
| 227 | 227 |
| 228 Future<_HttpParser> consume(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( |
| 236 _onData, | 236 _onData, |
| 237 onError: _onError, | 237 onError: _onError, |
| 238 onDone: () { | 238 onDone: () { |
| 239 _onDone(); | |
| 240 completer.complete(this); | 239 completer.complete(this); |
| 241 }); | 240 }); |
| 242 return completer.future; | 241 return completer.future; |
| 243 } | 242 } |
| 244 | 243 |
| 245 Future<_HttpParser> addStream(Stream<List<int>> stream) { | |
| 246 throw new UnimplementedError("_HttpParser.addStream"); | |
| 247 } | |
| 248 | |
| 249 Future<_HttpParser> close() { | 244 Future<_HttpParser> close() { |
| 250 throw new UnimplementedError("_HttpParser.close"); | 245 _onDone(); |
| 246 return new Future.immediate(this); |
| 251 } | 247 } |
| 252 | 248 |
| 253 // From RFC 2616. | 249 // From RFC 2616. |
| 254 // generic-message = start-line | 250 // generic-message = start-line |
| 255 // *(message-header CRLF) | 251 // *(message-header CRLF) |
| 256 // CRLF | 252 // CRLF |
| 257 // [ message-body ] | 253 // [ message-body ] |
| 258 // start-line = Request-Line | Status-Line | 254 // start-line = Request-Line | Status-Line |
| 259 // Request-Line = Method SP Request-URI SP HTTP-Version CRLF | 255 // Request-Line = Method SP Request-URI SP HTTP-Version CRLF |
| 260 // Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF | 256 // Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 StreamController<_HttpIncoming> _controller; | 975 StreamController<_HttpIncoming> _controller; |
| 980 StreamController<List<int>> _bodyController; | 976 StreamController<List<int>> _bodyController; |
| 981 } | 977 } |
| 982 | 978 |
| 983 | 979 |
| 984 class HttpParserException implements Exception { | 980 class HttpParserException implements Exception { |
| 985 const HttpParserException([String this.message = ""]); | 981 const HttpParserException([String this.message = ""]); |
| 986 String toString() => "HttpParserException: $message"; | 982 String toString() => "HttpParserException: $message"; |
| 987 final String message; | 983 final String message; |
| 988 } | 984 } |
| OLD | NEW |