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 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 int expectedBytesReceived: 0, | 30 int expectedBytesReceived: 0, |
31 Map expectedHeaders: null, | 31 Map expectedHeaders: null, |
32 bool chunked: false, | 32 bool chunked: false, |
33 bool upgrade: false, | 33 bool upgrade: false, |
34 int unparsedLength: 0, | 34 int unparsedLength: 0, |
35 bool connectionClose: false, | 35 bool connectionClose: false, |
36 String expectedVersion: "1.1"}) { | 36 String expectedVersion: "1.1"}) { |
37 StreamController controller; | 37 StreamController controller; |
38 void reset() { | 38 void reset() { |
39 _HttpParser httpParser = new _HttpParser.requestParser(); | 39 _HttpParser httpParser = new _HttpParser.requestParser(); |
40 controller = new StreamController(); | 40 controller = new StreamController(sync: true); |
41 var port1 = new ReceivePort(); | 41 var port1 = new ReceivePort(); |
42 var port2 = new ReceivePort(); | 42 var port2 = new ReceivePort(); |
43 | 43 |
44 String method; | 44 String method; |
45 Uri uri; | 45 Uri uri; |
46 HttpHeaders headers; | 46 HttpHeaders headers; |
47 int contentLength; | 47 int contentLength; |
48 int bytesReceived; | 48 int bytesReceived; |
49 int unparsedBytesReceived; | 49 int unparsedBytesReceived; |
50 bool upgraded; | 50 bool upgraded; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 testWrite(requestData, 1); | 128 testWrite(requestData, 1); |
129 } | 129 } |
130 | 130 |
131 static void _testParseInvalidRequest(String request) { | 131 static void _testParseInvalidRequest(String request) { |
132 _HttpParser httpParser; | 132 _HttpParser httpParser; |
133 bool errorCalled; | 133 bool errorCalled; |
134 StreamController controller; | 134 StreamController controller; |
135 | 135 |
136 void reset() { | 136 void reset() { |
137 httpParser = new _HttpParser.requestParser(); | 137 httpParser = new _HttpParser.requestParser(); |
138 controller = new StreamController(); | 138 controller = new StreamController(sync: true); |
139 var port = new ReceivePort(); | 139 var port = new ReceivePort(); |
140 controller.stream.pipe(httpParser); | 140 controller.stream.pipe(httpParser); |
141 var subscription = httpParser.listen((incoming) { | 141 var subscription = httpParser.listen((incoming) { |
142 Expect.fail("Expected request"); | 142 Expect.fail("Expected request"); |
143 }); | 143 }); |
144 subscription.onError((e) { | 144 subscription.onError((e) { |
145 errorCalled = true; | 145 errorCalled = true; |
146 }); | 146 }); |
147 subscription.onDone(() { | 147 subscription.onDone(() { |
148 port.close(); | 148 port.close(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 _HttpParser httpParser; | 191 _HttpParser httpParser; |
192 bool headersCompleteCalled; | 192 bool headersCompleteCalled; |
193 bool dataEndCalled; | 193 bool dataEndCalled; |
194 bool dataEndClose; | 194 bool dataEndClose; |
195 int statusCode; | 195 int statusCode; |
196 String reasonPhrase; | 196 String reasonPhrase; |
197 HttpHeaders headers; | 197 HttpHeaders headers; |
198 int contentLength; | 198 int contentLength; |
199 int bytesReceived; | 199 int bytesReceived; |
200 httpParser = new _HttpParser.responseParser(); | 200 httpParser = new _HttpParser.responseParser(); |
201 controller = new StreamController(); | 201 controller = new StreamController(sync: true); |
202 var port = new ReceivePort(); | 202 var port = new ReceivePort(); |
203 controller.stream.pipe(httpParser); | 203 controller.stream.pipe(httpParser); |
204 int doneCallCount = 0; | 204 int doneCallCount = 0; |
205 // Called when done parsing entire message and done parsing body. | 205 // Called when done parsing entire message and done parsing body. |
206 // Only executed when both are done. | 206 // Only executed when both are done. |
207 void whenDone() { | 207 void whenDone() { |
208 doneCallCount++; | 208 doneCallCount++; |
209 if (doneCallCount < 2) return; | 209 if (doneCallCount < 2) return; |
210 Expect.equals(expectedVersion, headers.protocolVersion); | 210 Expect.equals(expectedVersion, headers.protocolVersion); |
211 Expect.equals(expectedStatusCode, statusCode); | 211 Expect.equals(expectedStatusCode, statusCode); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // different chunks. | 273 // different chunks. |
274 List<int> responseData = response.codeUnits; | 274 List<int> responseData = response.codeUnits; |
275 testWrite(responseData); | 275 testWrite(responseData); |
276 testWrite(responseData, 10); | 276 testWrite(responseData, 10); |
277 testWrite(responseData, 1); | 277 testWrite(responseData, 1); |
278 } | 278 } |
279 | 279 |
280 static void _testParseInvalidResponse(String response, [bool close = false]) { | 280 static void _testParseInvalidResponse(String response, [bool close = false]) { |
281 void testWrite(List<int> requestData, [int chunkSize = -1]) { | 281 void testWrite(List<int> requestData, [int chunkSize = -1]) { |
282 _HttpParser httpParser = new _HttpParser.responseParser(); | 282 _HttpParser httpParser = new _HttpParser.responseParser(); |
283 StreamController controller = new StreamController(); | 283 StreamController controller = new StreamController(sync: true); |
284 bool errorCalled = false;; | 284 bool errorCalled = false;; |
285 | 285 |
286 if (chunkSize == -1) chunkSize = requestData.length; | 286 if (chunkSize == -1) chunkSize = requestData.length; |
287 | 287 |
288 var port = new ReceivePort(); | 288 var port = new ReceivePort(); |
289 controller.stream.pipe(httpParser); | 289 controller.stream.pipe(httpParser); |
290 var subscription = httpParser.listen((incoming) { | 290 var subscription = httpParser.listen((incoming) { |
291 incoming.listen( | 291 incoming.listen( |
292 (data) {}, | 292 (data) {}, |
293 onError: (e) { | 293 onError: (e) { |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 0123456789012345678901234567890\r | 870 0123456789012345678901234567890\r |
871 0\r\n\r\n"""; | 871 0\r\n\r\n"""; |
872 _testParseInvalidResponse(response); | 872 _testParseInvalidResponse(response); |
873 } | 873 } |
874 } | 874 } |
875 | 875 |
876 | 876 |
877 void main() { | 877 void main() { |
878 HttpParserTest.runAllTests(); | 878 HttpParserTest.runAllTests(); |
879 } | 879 } |
OLD | NEW |