| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 class _HttpDetachedIncoming extends Stream<List<int>> { | 98 class _HttpDetachedIncoming extends Stream<List<int>> { |
| 99 StreamController<List<int>> controller; | 99 StreamController<List<int>> controller; |
| 100 final StreamSubscription subscription; | 100 final StreamSubscription subscription; |
| 101 | 101 |
| 102 List<int> carryOverData; | 102 List<int> carryOverData; |
| 103 bool paused; | 103 bool paused; |
| 104 | 104 |
| 105 Completer resumeCompleter; | 105 Completer resumeCompleter; |
| 106 | 106 |
| 107 _HttpDetachedIncoming(StreamSubscription this.subscription, | 107 _HttpDetachedIncoming(StreamSubscription this.subscription, |
| 108 List<int> this.carryOverData, | 108 List<int> this.carryOverData) { |
| 109 Completer oldResumeCompleter) { | |
| 110 controller = new StreamController<List<int>>( | 109 controller = new StreamController<List<int>>( |
| 111 onListen: resume, | 110 onListen: resume, |
| 112 onPause: pause, | 111 onPause: pause, |
| 113 onResume: resume, | 112 onResume: resume, |
| 114 onCancel: () => subscription.cancel()); | 113 onCancel: () => subscription.cancel()); |
| 115 if (subscription == null) { | 114 if (subscription == null) { |
| 116 // Socket was already closed. | 115 // Socket was already closed. |
| 117 if (carryOverData != null) controller.add(carryOverData); | 116 if (carryOverData != null) controller.add(carryOverData); |
| 118 controller.close(); | 117 controller.close(); |
| 119 } else { | 118 } else { |
| 120 pause(); | 119 pause(); |
| 121 if (oldResumeCompleter != null) oldResumeCompleter.complete(); | |
| 122 subscription.resume(); | 120 subscription.resume(); |
| 123 subscription.onData(controller.add); | 121 subscription.onData(controller.add); |
| 124 subscription.onDone(controller.close); | 122 subscription.onDone(controller.close); |
| 125 subscription.onError(controller.addError); | 123 subscription.onError(controller.addError); |
| 126 } | 124 } |
| 127 } | 125 } |
| 128 | 126 |
| 129 StreamSubscription<List<int>> listen(void onData(List<int> event), | 127 StreamSubscription<List<int>> listen(void onData(List<int> event), |
| 130 {void onError(error), | 128 {void onError(error), |
| 131 void onDone(), | 129 void onDone(), |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 } | 783 } |
| 786 | 784 |
| 787 int get messageType => _messageType; | 785 int get messageType => _messageType; |
| 788 int get transferLength => _transferLength; | 786 int get transferLength => _transferLength; |
| 789 bool get upgrade => _connectionUpgrade && _state == _State.UPGRADED; | 787 bool get upgrade => _connectionUpgrade && _state == _State.UPGRADED; |
| 790 bool get persistentConnection => _persistentConnection; | 788 bool get persistentConnection => _persistentConnection; |
| 791 | 789 |
| 792 void set responseToMethod(String method) { _responseToMethod = method; } | 790 void set responseToMethod(String method) { _responseToMethod = method; } |
| 793 | 791 |
| 794 _HttpDetachedIncoming detachIncoming() { | 792 _HttpDetachedIncoming detachIncoming() { |
| 795 var completer = _pauseCompleter; | |
| 796 _pauseCompleter = null; | |
| 797 return new _HttpDetachedIncoming(_socketSubscription, | 793 return new _HttpDetachedIncoming(_socketSubscription, |
| 798 readUnparsedData(), | 794 readUnparsedData()); |
| 799 completer); | |
| 800 } | 795 } |
| 801 | 796 |
| 802 List<int> readUnparsedData() { | 797 List<int> readUnparsedData() { |
| 803 if (_buffer == null) return null; | 798 if (_buffer == null) return null; |
| 804 if (_index == _buffer.length) return null; | 799 if (_index == _buffer.length) return null; |
| 805 var result = _buffer.sublist(_index); | 800 var result = _buffer.sublist(_index); |
| 806 _releaseBuffer(); | 801 _releaseBuffer(); |
| 807 return result; | 802 return result; |
| 808 } | 803 } |
| 809 | 804 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 String _responseToMethod; // Indicates the method used for the request. | 981 String _responseToMethod; // Indicates the method used for the request. |
| 987 int _remainingContent; | 982 int _remainingContent; |
| 988 | 983 |
| 989 _HttpHeaders _headers; | 984 _HttpHeaders _headers; |
| 990 | 985 |
| 991 // The current incoming connection. | 986 // The current incoming connection. |
| 992 _HttpIncoming _incoming; | 987 _HttpIncoming _incoming; |
| 993 StreamSubscription _socketSubscription; | 988 StreamSubscription _socketSubscription; |
| 994 bool _paused = true; | 989 bool _paused = true; |
| 995 bool _bodyPaused = false; | 990 bool _bodyPaused = false; |
| 996 Completer _pauseCompleter; | |
| 997 StreamController<_HttpIncoming> _controller; | 991 StreamController<_HttpIncoming> _controller; |
| 998 StreamController<List<int>> _bodyController; | 992 StreamController<List<int>> _bodyController; |
| 999 } | 993 } |
| 1000 | 994 |
| 1001 | 995 |
| 1002 class HttpParserException implements Exception { | 996 class HttpParserException implements Exception { |
| 1003 const HttpParserException([String this.message = ""]); | 997 const HttpParserException([String this.message = ""]); |
| 1004 String toString() => "HttpParserException: $message"; | 998 String toString() => "HttpParserException: $message"; |
| 1005 final String message; | 999 final String message; |
| 1006 } | 1000 } |
| OLD | NEW |