| 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 library dart.io; | 5 library dart.io; |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import "dart:async"; | 8 import "dart:async"; |
| 9 import "dart:collection"; | 9 import "dart:collection"; |
| 10 import "dart:convert"; | 10 import "dart:convert"; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 var port2 = new ReceivePort(); | 63 var port2 = new ReceivePort(); |
| 64 | 64 |
| 65 String method; | 65 String method; |
| 66 Uri uri; | 66 Uri uri; |
| 67 _HttpHeaders headers; | 67 _HttpHeaders headers; |
| 68 int contentLength; | 68 int contentLength; |
| 69 int bytesReceived; | 69 int bytesReceived; |
| 70 int unparsedBytesReceived; | 70 int unparsedBytesReceived; |
| 71 bool upgraded; | 71 bool upgraded; |
| 72 | 72 |
| 73 controller.stream.pipe(httpParser); | 73 httpParser.listenToStream(controller.stream); |
| 74 var subscription = httpParser.listen((incoming) { | 74 var subscription = httpParser.listen((incoming) { |
| 75 method = incoming.method; | 75 method = incoming.method; |
| 76 uri = incoming.uri; | 76 uri = incoming.uri; |
| 77 headers = incoming.headers; | 77 headers = incoming.headers; |
| 78 upgraded = incoming.upgraded; | 78 upgraded = incoming.upgraded; |
| 79 Expect.equals(upgrade, upgraded); | 79 Expect.equals(upgrade, upgraded); |
| 80 | 80 |
| 81 if (!chunked) { | 81 if (!chunked) { |
| 82 Expect.equals(expectedTransferLength, incoming.transferLength); | 82 Expect.equals(expectedTransferLength, incoming.transferLength); |
| 83 } else { | 83 } else { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 static void _testParseInvalidRequest(String request) { | 152 static void _testParseInvalidRequest(String request) { |
| 153 _HttpParser httpParser; | 153 _HttpParser httpParser; |
| 154 bool errorCalled; | 154 bool errorCalled; |
| 155 StreamController controller; | 155 StreamController controller; |
| 156 | 156 |
| 157 void reset() { | 157 void reset() { |
| 158 httpParser = new _HttpParser.requestParser(); | 158 httpParser = new _HttpParser.requestParser(); |
| 159 controller = new StreamController(sync: true); | 159 controller = new StreamController(sync: true); |
| 160 var port = new ReceivePort(); | 160 var port = new ReceivePort(); |
| 161 controller.stream.pipe(httpParser); | 161 httpParser.listenToStream(controller.stream); |
| 162 var subscription = httpParser.listen((incoming) { | 162 var subscription = httpParser.listen((incoming) { |
| 163 Expect.fail("Expected request"); | 163 Expect.fail("Expected request"); |
| 164 }); | 164 }); |
| 165 subscription.onError((e) { | 165 subscription.onError((e) { |
| 166 errorCalled = true; | 166 errorCalled = true; |
| 167 }); | 167 }); |
| 168 subscription.onDone(() { | 168 subscription.onDone(() { |
| 169 port.close(); | 169 port.close(); |
| 170 Expect.isTrue(errorCalled); | 170 Expect.isTrue(errorCalled); |
| 171 }); | 171 }); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 bool dataEndCalled; | 214 bool dataEndCalled; |
| 215 bool dataEndClose; | 215 bool dataEndClose; |
| 216 int statusCode; | 216 int statusCode; |
| 217 String reasonPhrase; | 217 String reasonPhrase; |
| 218 _HttpHeaders headers; | 218 _HttpHeaders headers; |
| 219 int contentLength; | 219 int contentLength; |
| 220 int bytesReceived; | 220 int bytesReceived; |
| 221 httpParser = new _HttpParser.responseParser(); | 221 httpParser = new _HttpParser.responseParser(); |
| 222 controller = new StreamController(sync: true); | 222 controller = new StreamController(sync: true); |
| 223 var port = new ReceivePort(); | 223 var port = new ReceivePort(); |
| 224 controller.stream.pipe(httpParser); | 224 httpParser.listenToStream(controller.stream); |
| 225 int doneCallCount = 0; | 225 int doneCallCount = 0; |
| 226 // Called when done parsing entire message and done parsing body. | 226 // Called when done parsing entire message and done parsing body. |
| 227 // Only executed when both are done. | 227 // Only executed when both are done. |
| 228 void whenDone() { | 228 void whenDone() { |
| 229 doneCallCount++; | 229 doneCallCount++; |
| 230 if (doneCallCount < 2) return; | 230 if (doneCallCount < 2) return; |
| 231 Expect.equals(expectedVersion, headers.protocolVersion); | 231 Expect.equals(expectedVersion, headers.protocolVersion); |
| 232 Expect.equals(expectedStatusCode, statusCode); | 232 Expect.equals(expectedStatusCode, statusCode); |
| 233 Expect.equals(expectedReasonPhrase, reasonPhrase); | 233 Expect.equals(expectedReasonPhrase, reasonPhrase); |
| 234 Expect.isTrue(headersCompleteCalled); | 234 Expect.isTrue(headersCompleteCalled); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 300 |
| 301 static void _testParseInvalidResponse(String response, [bool close = false]) { | 301 static void _testParseInvalidResponse(String response, [bool close = false]) { |
| 302 void testWrite(List<int> requestData, [int chunkSize = -1]) { | 302 void testWrite(List<int> requestData, [int chunkSize = -1]) { |
| 303 _HttpParser httpParser = new _HttpParser.responseParser(); | 303 _HttpParser httpParser = new _HttpParser.responseParser(); |
| 304 StreamController controller = new StreamController(sync: true); | 304 StreamController controller = new StreamController(sync: true); |
| 305 bool errorCalled = false;; | 305 bool errorCalled = false;; |
| 306 | 306 |
| 307 if (chunkSize == -1) chunkSize = requestData.length; | 307 if (chunkSize == -1) chunkSize = requestData.length; |
| 308 | 308 |
| 309 var port = new ReceivePort(); | 309 var port = new ReceivePort(); |
| 310 controller.stream.pipe(httpParser); | 310 httpParser.listenToStream(controller.stream); |
| 311 var subscription = httpParser.listen((incoming) { | 311 var subscription = httpParser.listen((incoming) { |
| 312 incoming.listen( | 312 incoming.listen( |
| 313 (data) {}, | 313 (data) {}, |
| 314 onError: (e) { | 314 onError: (e) { |
| 315 Expect.isFalse(errorCalled); | 315 Expect.isFalse(errorCalled); |
| 316 errorCalled = true; | 316 errorCalled = true; |
| 317 }); | 317 }); |
| 318 }); | 318 }); |
| 319 subscription.onError((e) { | 319 subscription.onError((e) { |
| 320 Expect.isFalse(errorCalled); | 320 Expect.isFalse(errorCalled); |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 0123456789012345678901234567890\r | 891 0123456789012345678901234567890\r |
| 892 0\r\n\r\n"""; | 892 0\r\n\r\n"""; |
| 893 _testParseInvalidResponse(response); | 893 _testParseInvalidResponse(response); |
| 894 } | 894 } |
| 895 } | 895 } |
| 896 | 896 |
| 897 | 897 |
| 898 void main() { | 898 void main() { |
| 899 HttpParserTest.runAllTests(); | 899 HttpParserTest.runAllTests(); |
| 900 } | 900 } |
| OLD | NEW |