| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 import 'dart:typed_data'; | 8 import 'dart:typed_data'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 bool dataEndClose; | 195 bool dataEndClose; |
| 196 int statusCode; | 196 int statusCode; |
| 197 String reasonPhrase; | 197 String reasonPhrase; |
| 198 HttpHeaders headers; | 198 HttpHeaders headers; |
| 199 int contentLength; | 199 int contentLength; |
| 200 int bytesReceived; | 200 int bytesReceived; |
| 201 httpParser = new _HttpParser.responseParser(); | 201 httpParser = new _HttpParser.responseParser(); |
| 202 controller = new StreamController(); | 202 controller = new StreamController(); |
| 203 var port = new ReceivePort(); | 203 var port = new ReceivePort(); |
| 204 controller.stream.pipe(httpParser); | 204 controller.stream.pipe(httpParser); |
| 205 int doneCallCount = 0; |
| 206 // Called when done parsing entire message and done parsing body. |
| 207 // Only executed when both are done. |
| 208 void whenDone() { |
| 209 doneCallCount++; |
| 210 if (doneCallCount < 2) return; |
| 211 Expect.equals(expectedVersion, headers.protocolVersion); |
| 212 Expect.equals(expectedStatusCode, statusCode); |
| 213 Expect.equals(expectedReasonPhrase, reasonPhrase); |
| 214 Expect.isTrue(headersCompleteCalled); |
| 215 Expect.equals(expectedBytesReceived, bytesReceived); |
| 216 if (!upgrade) { |
| 217 Expect.isTrue(dataEndCalled); |
| 218 if (close) Expect.isTrue(dataEndClose); |
| 219 Expect.equals(dataEndClose, connectionClose); |
| 220 } |
| 221 }; |
| 222 |
| 205 var subscription = httpParser.listen((incoming) { | 223 var subscription = httpParser.listen((incoming) { |
| 206 port.close(); | 224 port.close(); |
| 207 statusCode = incoming.statusCode; | 225 statusCode = incoming.statusCode; |
| 208 reasonPhrase = incoming.reasonPhrase; | 226 reasonPhrase = incoming.reasonPhrase; |
| 209 headers = incoming.headers; | 227 headers = incoming.headers; |
| 210 Expect.isFalse(headersCompleteCalled); | 228 Expect.isFalse(headersCompleteCalled); |
| 211 if (!chunked && !close) { | 229 if (!chunked && !close) { |
| 212 Expect.equals(expectedTransferLength, incoming.transferLength); | 230 Expect.equals(expectedTransferLength, incoming.transferLength); |
| 213 } else { | 231 } else { |
| 214 Expect.equals(-1, incoming.transferLength); | 232 Expect.equals(-1, incoming.transferLength); |
| 215 } | 233 } |
| 216 if (expectedHeaders != null) { | 234 if (expectedHeaders != null) { |
| 217 expectedHeaders.forEach((String name, String value) { | 235 expectedHeaders.forEach((String name, String value) { |
| 218 Expect.equals(value, headers[name][0]); | 236 Expect.equals(value, headers[name][0]); |
| 219 }); | 237 }); |
| 220 } | 238 } |
| 221 Expect.equals(upgrade, httpParser.upgrade); | 239 Expect.equals(upgrade, httpParser.upgrade); |
| 222 headersCompleteCalled = true; | 240 headersCompleteCalled = true; |
| 223 incoming.listen( | 241 incoming.listen( |
| 224 (List<int> data) { | 242 (List<int> data) { |
| 225 Expect.isTrue(headersCompleteCalled); | 243 Expect.isTrue(headersCompleteCalled); |
| 226 bytesReceived += data.length; | 244 bytesReceived += data.length; |
| 227 }, | 245 }, |
| 228 onDone: () { | 246 onDone: () { |
| 229 dataEndCalled = true; | 247 dataEndCalled = true; |
| 230 dataEndClose = close; | 248 dataEndClose = close; |
| 249 whenDone(); |
| 231 }); | 250 }); |
| 232 }); | 251 }, onDone: whenDone); |
| 233 | |
| 234 subscription.onDone(() { | |
| 235 Expect.equals(expectedVersion, headers.protocolVersion); | |
| 236 Expect.equals(expectedStatusCode, statusCode); | |
| 237 Expect.equals(expectedReasonPhrase, reasonPhrase); | |
| 238 Expect.isTrue(headersCompleteCalled); | |
| 239 Expect.equals(expectedBytesReceived, bytesReceived); | |
| 240 if (!upgrade) { | |
| 241 Expect.isTrue(dataEndCalled); | |
| 242 if (close) Expect.isTrue(dataEndClose); | |
| 243 Expect.equals(dataEndClose, connectionClose); | |
| 244 } | |
| 245 }); | |
| 246 | 252 |
| 247 headersCompleteCalled = false; | 253 headersCompleteCalled = false; |
| 248 dataEndCalled = false; | 254 dataEndCalled = false; |
| 249 dataEndClose = null; | 255 dataEndClose = null; |
| 250 statusCode = -1; | 256 statusCode = -1; |
| 251 reasonPhrase = null; | 257 reasonPhrase = null; |
| 252 headers = null; | 258 headers = null; |
| 253 bytesReceived = 0; | 259 bytesReceived = 0; |
| 254 } | 260 } |
| 255 | 261 |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 0123456789012345678901234567890\r | 871 0123456789012345678901234567890\r |
| 866 0\r\n\r\n"""; | 872 0\r\n\r\n"""; |
| 867 _testParseInvalidResponse(response); | 873 _testParseInvalidResponse(response); |
| 868 } | 874 } |
| 869 } | 875 } |
| 870 | 876 |
| 871 | 877 |
| 872 void main() { | 878 void main() { |
| 873 HttpParserTest.runAllTests(); | 879 HttpParserTest.runAllTests(); |
| 874 } | 880 } |
| OLD | NEW |