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