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 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:math'; | 6 import 'dart:math'; |
7 import 'dart:scalarlist'; | 7 import 'dart:scalarlist'; |
8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
9 import 'dart:uri'; | 9 import 'dart:uri'; |
10 | 10 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 headers = null; | 109 headers = null; |
110 bytesReceived = 0; | 110 bytesReceived = 0; |
111 unparsedBytesReceived = 0; | 111 unparsedBytesReceived = 0; |
112 upgraded = false; | 112 upgraded = false; |
113 } | 113 } |
114 | 114 |
115 void testWrite(List<int> requestData, [int chunkSize = -1]) { | 115 void testWrite(List<int> requestData, [int chunkSize = -1]) { |
116 if (chunkSize == -1) chunkSize = requestData.length; | 116 if (chunkSize == -1) chunkSize = requestData.length; |
117 reset(); | 117 reset(); |
118 for (int pos = 0; pos < requestData.length; pos += chunkSize) { | 118 for (int pos = 0; pos < requestData.length; pos += chunkSize) { |
119 int remaining = requestData.length - pos; | 119 int end = min(requestData.length, pos + chunkSize); |
120 int writeLength = min(chunkSize, remaining); | 120 controller.add(requestData.sublist(pos, end)); |
121 controller.add(requestData.getRange(pos, writeLength)); | |
122 } | 121 } |
123 controller.close(); | 122 controller.close(); |
124 } | 123 } |
125 | 124 |
126 // Test parsing the request three times delivering the data in | 125 // Test parsing the request three times delivering the data in |
127 // different chunks. | 126 // different chunks. |
128 List<int> requestData = request.codeUnits; | 127 List<int> requestData = request.codeUnits; |
129 testWrite(requestData); | 128 testWrite(requestData); |
130 testWrite(requestData, 10); | 129 testWrite(requestData, 10); |
131 testWrite(requestData, 1); | 130 testWrite(requestData, 1); |
(...skipping 21 matching lines...) Expand all Loading... |
153 }); | 152 }); |
154 errorCalled = false; | 153 errorCalled = false; |
155 } | 154 } |
156 | 155 |
157 void testWrite(List<int> requestData, [int chunkSize = -1]) { | 156 void testWrite(List<int> requestData, [int chunkSize = -1]) { |
158 if (chunkSize == -1) chunkSize = requestData.length; | 157 if (chunkSize == -1) chunkSize = requestData.length; |
159 reset(); | 158 reset(); |
160 for (int pos = 0; | 159 for (int pos = 0; |
161 pos < requestData.length && !errorCalled; | 160 pos < requestData.length && !errorCalled; |
162 pos += chunkSize) { | 161 pos += chunkSize) { |
163 int remaining = requestData.length - pos; | 162 int end = min(requestData.length, pos + chunkSize); |
164 int writeLength = min(chunkSize, remaining); | 163 controller.add(requestData.sublist(pos, end)); |
165 controller.add(requestData.getRange(pos, writeLength)); | |
166 } | 164 } |
167 controller.close(); | 165 controller.close(); |
168 } | 166 } |
169 | 167 |
170 // Test parsing the request three times delivering the data in | 168 // Test parsing the request three times delivering the data in |
171 // different chunks. | 169 // different chunks. |
172 List<int> requestData = request.codeUnits; | 170 List<int> requestData = request.codeUnits; |
173 testWrite(requestData); | 171 testWrite(requestData); |
174 testWrite(requestData, 10); | 172 testWrite(requestData, 10); |
175 testWrite(requestData, 1); | 173 testWrite(requestData, 1); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 statusCode = -1; | 251 statusCode = -1; |
254 reasonPhrase = null; | 252 reasonPhrase = null; |
255 headers = null; | 253 headers = null; |
256 bytesReceived = 0; | 254 bytesReceived = 0; |
257 } | 255 } |
258 | 256 |
259 void testWrite(List<int> requestData, [int chunkSize = -1]) { | 257 void testWrite(List<int> requestData, [int chunkSize = -1]) { |
260 if (chunkSize == -1) chunkSize = requestData.length; | 258 if (chunkSize == -1) chunkSize = requestData.length; |
261 reset(); | 259 reset(); |
262 for (int pos = 0; pos < requestData.length; pos += chunkSize) { | 260 for (int pos = 0; pos < requestData.length; pos += chunkSize) { |
263 int remaining = requestData.length - pos; | 261 int end = min(requestData.length, pos + chunkSize); |
264 int writeLength = min(chunkSize, remaining); | 262 controller.add(requestData.sublist(pos, end)); |
265 controller.add(requestData.getRange(pos, writeLength)); | |
266 | 263 |
267 } | 264 } |
268 if (close) controller.close(); | 265 if (close) controller.close(); |
269 } | 266 } |
270 | 267 |
271 // Test parsing the request three times delivering the data in | 268 // Test parsing the request three times delivering the data in |
272 // different chunks. | 269 // different chunks. |
273 List<int> responseData = response.codeUnits; | 270 List<int> responseData = response.codeUnits; |
274 testWrite(responseData); | 271 testWrite(responseData); |
275 testWrite(responseData, 10); | 272 testWrite(responseData, 10); |
(...skipping 28 matching lines...) Expand all Loading... |
304 }); | 301 }); |
305 errorCalled = false; | 302 errorCalled = false; |
306 } | 303 } |
307 | 304 |
308 void testWrite(List<int> requestData, [int chunkSize = -1]) { | 305 void testWrite(List<int> requestData, [int chunkSize = -1]) { |
309 if (chunkSize == -1) chunkSize = requestData.length; | 306 if (chunkSize == -1) chunkSize = requestData.length; |
310 reset(); | 307 reset(); |
311 for (int pos = 0; | 308 for (int pos = 0; |
312 pos < requestData.length && !errorCalled; | 309 pos < requestData.length && !errorCalled; |
313 pos += chunkSize) { | 310 pos += chunkSize) { |
314 int remaining = requestData.length - pos; | 311 int end = min(requestData.length, pos + chunkSize); |
315 int writeLength = min(chunkSize, remaining); | 312 controller.add(requestData.sublist(pos, end)); |
316 controller.add(requestData.getRange(pos, writeLength)); | |
317 } | 313 } |
318 controller.close(); | 314 controller.close(); |
319 } | 315 } |
320 | 316 |
321 // Test parsing the request three times delivering the data in | 317 // Test parsing the request three times delivering the data in |
322 // different chunks. | 318 // different chunks. |
323 List<int> responseData = response.codeUnits; | 319 List<int> responseData = response.codeUnits; |
324 testWrite(responseData); | 320 testWrite(responseData); |
325 testWrite(responseData, 10); | 321 testWrite(responseData, 10); |
326 testWrite(responseData, 1); | 322 testWrite(responseData, 1); |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 0123456789012345678901234567890\r | 870 0123456789012345678901234567890\r |
875 0\r\n\r\n"""; | 871 0\r\n\r\n"""; |
876 _testParseInvalidResponse(response); | 872 _testParseInvalidResponse(response); |
877 } | 873 } |
878 } | 874 } |
879 | 875 |
880 | 876 |
881 void main() { | 877 void main() { |
882 HttpParserTest.runAllTests(); | 878 HttpParserTest.runAllTests(); |
883 } | 879 } |
OLD | NEW |