OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 // |
| 5 // VMOptions= |
| 6 // VMOptions=--short_socket_read |
| 7 // VMOptions=--short_socket_write |
| 8 // VMOptions=--short_socket_read --short_socket_write |
| 9 |
| 10 import 'dart:io'; |
| 11 import 'dart:typed_data'; |
| 12 |
| 13 import 'package:expect/expect.dart'; |
| 14 |
| 15 void testChunkedBufferSizeMsg() { |
| 16 // Buffer of same size as our internal buffer, minus 4. Makes us hit the |
| 17 // boundary. |
| 18 var sendData = new Uint8List(8 * 1024 - 4); |
| 19 for (int i = 0; i < sendData.length; i++) sendData[i] = i % 256; |
| 20 |
| 21 HttpServer.bind('127.0.0.1', 0).then((server) { |
| 22 server.listen((request) { |
| 23 // Chunked is on by default. Be sure no data is lost when sending several |
| 24 // chunks of data. |
| 25 request.response.add(sendData); |
| 26 request.response.add(sendData); |
| 27 request.response.add(sendData); |
| 28 request.response.add(sendData); |
| 29 request.response.add(sendData); |
| 30 request.response.add(sendData); |
| 31 request.response.add(sendData); |
| 32 request.response.add(sendData); |
| 33 request.response.close(); |
| 34 }); |
| 35 var client = new HttpClient(); |
| 36 client.get('127.0.0.1', server.port, '/') |
| 37 .then((request) { |
| 38 request.headers.set(HttpHeaders.ACCEPT_ENCODING, ""); |
| 39 return request.close(); |
| 40 }) |
| 41 .then((response) { |
| 42 var buffer = []; |
| 43 response.listen( |
| 44 (data) => buffer.addAll(data), |
| 45 onDone: () { |
| 46 Expect.equals(sendData.length * 8, buffer.length); |
| 47 for (int i = 0; i < buffer.length; i++) { |
| 48 Expect.equals(sendData[i % sendData.length], buffer[i]); |
| 49 } |
| 50 server.close(); |
| 51 }); |
| 52 }); |
| 53 }); |
| 54 } |
| 55 |
| 56 |
| 57 void main() { |
| 58 testChunkedBufferSizeMsg(); |
| 59 } |
OLD | NEW |