| 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 } | 314 } |
| 315 | 315 |
| 316 void listenToStream(Stream<List<int>> stream) { | 316 void listenToStream(Stream<List<int>> stream) { |
| 317 // Listen to the stream and handle data accordingly. When a | 317 // Listen to the stream and handle data accordingly. When a |
| 318 // _HttpIncoming is created, _dataPause, _dataResume, _dataDone is | 318 // _HttpIncoming is created, _dataPause, _dataResume, _dataDone is |
| 319 // given to provide a way of controlling the parser. | 319 // given to provide a way of controlling the parser. |
| 320 // TODO(ajohnsen): Remove _dataPause, _dataResume and _dataDone and clean up | 320 // TODO(ajohnsen): Remove _dataPause, _dataResume and _dataDone and clean up |
| 321 // how the _HttpIncoming signals the parser. | 321 // how the _HttpIncoming signals the parser. |
| 322 _socketSubscription = stream.listen( | 322 _socketSubscription = stream.listen( |
| 323 _onData, | 323 _onData, |
| 324 onError: _onError, | 324 onError: _controller.addError, |
| 325 onDone: _onDone); | 325 onDone: _onDone); |
| 326 } | 326 } |
| 327 | 327 |
| 328 void _parse() { | 328 void _parse() { |
| 329 try { | 329 try { |
| 330 _doParse(); | 330 _doParse(); |
| 331 } catch (e, s) { | 331 } catch (e, s) { |
| 332 _state = _State.FAILURE; | 332 _state = _State.FAILURE; |
| 333 _reportError(e, s); | 333 _reportError(e, s); |
| 334 } | 334 } |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 } else { | 838 } else { |
| 839 _state = _State.FAILURE; | 839 _state = _State.FAILURE; |
| 840 // Report the error through the error callback if any. Otherwise | 840 // Report the error through the error callback if any. Otherwise |
| 841 // throw the error. | 841 // throw the error. |
| 842 _reportError(new HttpException( | 842 _reportError(new HttpException( |
| 843 "Connection closed before full body was received")); | 843 "Connection closed before full body was received")); |
| 844 } | 844 } |
| 845 _controller.close(); | 845 _controller.close(); |
| 846 } | 846 } |
| 847 | 847 |
| 848 void _onError(e, [StackTrace stackTrace]) { | |
| 849 _controller.addError(e, stackTrace); | |
| 850 } | |
| 851 | |
| 852 String get version { | 848 String get version { |
| 853 switch (_httpVersion) { | 849 switch (_httpVersion) { |
| 854 case _HttpVersion.HTTP10: | 850 case _HttpVersion.HTTP10: |
| 855 return "1.0"; | 851 return "1.0"; |
| 856 case _HttpVersion.HTTP11: | 852 case _HttpVersion.HTTP11: |
| 857 return "1.1"; | 853 return "1.1"; |
| 858 } | 854 } |
| 859 return null; | 855 return null; |
| 860 } | 856 } |
| 861 | 857 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 } | 1035 } |
| 1040 } | 1036 } |
| 1041 | 1037 |
| 1042 void _reportError(error, [stackTrace]) { | 1038 void _reportError(error, [stackTrace]) { |
| 1043 if (_socketSubscription != null) _socketSubscription.cancel(); | 1039 if (_socketSubscription != null) _socketSubscription.cancel(); |
| 1044 _state = _State.FAILURE; | 1040 _state = _State.FAILURE; |
| 1045 _controller.addError(error, stackTrace); | 1041 _controller.addError(error, stackTrace); |
| 1046 _controller.close(); | 1042 _controller.close(); |
| 1047 } | 1043 } |
| 1048 } | 1044 } |
| OLD | NEW |