Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: tests/standalone/io/regress_7097_test.dart

Issue 11447013: Correctly handle optional length in HTTP output stream writeFrom (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 import 'dart:io';
6 import 'dart:uri';
7
8 void main() {
9 var client = new HttpClient();
10 var server = new HttpServer();
11
12 var count = 0;
13 server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
14 List<int> data = [];
15 request.inputStream.onData = () {
16 data.addAll(request.inputStream.read());
17 };
18 request.inputStream.onClosed = () {
19 count++;
20 Expect.equals(count, data.length);
21 switch (count - 1) {
22 case 0:
23 response.outputStream.writeFrom([65, 66, 67], 1, 1);
24 break;
25 case 1:
26 response.outputStream.writeFrom([65, 66, 67], 1);
27 break;
28 case 2:
29 response.outputStream.writeFrom([65, 66, 67]);
30 break;
31 default:
32 Expect.fail("Unexpected state");
33 }
34 response.outputStream.close();
35 };
36 };
37 server.listen('127.0.0.1', 0);
38
39 Future makeRequest(int n) {
40 var completer = new Completer();
41 var url = new Uri.fromString("http://localhost:${server.port}");
42 var connection = client.openUrl("POST", url);
43 connection.onRequest = (HttpClientRequest request) {
44 request.contentLength = n + 1;
45 switch (n) {
46 case 0:
47 request.outputStream.writeFrom([65, 66, 67], 1, 1);
48 break;
49 case 1:
50 request.outputStream.writeFrom([65, 66, 67], 1);
51 break;
52 case 2:
53 request.outputStream.writeFrom([65, 66, 67]);
54 break;
55 default:
56 Expect.fail("Unexpected state");
57 }
58 request.outputStream.close();
59 };
60 connection.onResponse = (HttpClientResponse response) {
61 List<int> data = [];
62 response.inputStream.onData = () {
63 data.addAll(response.inputStream.read());
64 };
65 response.inputStream.onClosed = () {
66 Expect.equals(count, data.length);
67 completer.complete(null);
68 };
69 };
70 return completer.future;
71 }
72
73 makeRequest(0).then((_) {
74 makeRequest(1).then((_) {
75 makeRequest(2).then((_) {
76 client.shutdown();
77 server.close();
78 });
79 });
80 });
81 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698