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

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

Issue 11301034: Add flush to HTTP output streams (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | « runtime/bin/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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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 // VMOptions= 5 // VMOptions=
6 // VMOptions=--short_socket_read 6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write 7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write 8 // VMOptions=--short_socket_read --short_socket_write
9 9
10 #import("dart:isolate"); 10 #import("dart:isolate");
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 response.cookies.add(cookie2); 171 response.cookies.add(cookie2);
172 response.outputStream.close(); 172 response.outputStream.close();
173 } 173 }
174 174
175 void _cookie2Handler(HttpRequest request, HttpResponse response) { 175 void _cookie2Handler(HttpRequest request, HttpResponse response) {
176 // Two cookies passed with this request. 176 // Two cookies passed with this request.
177 Expect.equals(2, request.cookies.length); 177 Expect.equals(2, request.cookies.length);
178 response.outputStream.close(); 178 response.outputStream.close();
179 } 179 }
180 180
181 void _flushHandler(HttpRequest request, HttpResponse response) {
182 response.outputStream.flush();
183 response.outputStream.close();
184 }
185
181 void init() { 186 void init() {
182 // Setup request handlers. 187 // Setup request handlers.
183 _requestHandlers = new Map(); 188 _requestHandlers = new Map();
184 _requestHandlers["/host"] = 189 _requestHandlers["/host"] =
185 (HttpRequest request, HttpResponse response) { 190 (HttpRequest request, HttpResponse response) {
186 _hostHandler(request, response); 191 _hostHandler(request, response);
187 }; 192 };
188 _requestHandlers["/expires1"] = 193 _requestHandlers["/expires1"] =
189 (HttpRequest request, HttpResponse response) { 194 (HttpRequest request, HttpResponse response) {
190 _expires1Handler(request, response); 195 _expires1Handler(request, response);
(...skipping 11 matching lines...) Expand all
202 _contentType2Handler(request, response); 207 _contentType2Handler(request, response);
203 }; 208 };
204 _requestHandlers["/cookie1"] = 209 _requestHandlers["/cookie1"] =
205 (HttpRequest request, HttpResponse response) { 210 (HttpRequest request, HttpResponse response) {
206 _cookie1Handler(request, response); 211 _cookie1Handler(request, response);
207 }; 212 };
208 _requestHandlers["/cookie2"] = 213 _requestHandlers["/cookie2"] =
209 (HttpRequest request, HttpResponse response) { 214 (HttpRequest request, HttpResponse response) {
210 _cookie2Handler(request, response); 215 _cookie2Handler(request, response);
211 }; 216 };
217 _requestHandlers["/flush"] =
218 (HttpRequest request, HttpResponse response) {
219 _flushHandler(request, response);
220 };
212 } 221 }
213 222
214 void dispatch(message, replyTo) { 223 void dispatch(message, replyTo) {
215 if (message.isStart) { 224 if (message.isStart) {
216 _server = new HttpServer(); 225 _server = new HttpServer();
217 try { 226 try {
218 _server.listen("127.0.0.1", 0); 227 _server.listen("127.0.0.1", 0);
219 _server.defaultRequestHandler = (HttpRequest req, HttpResponse rsp) { 228 _server.defaultRequestHandler = (HttpRequest req, HttpResponse rsp) {
220 _requestReceivedHandler(req, rsp); 229 _requestReceivedHandler(req, rsp);
221 }; 230 };
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 }; 407 };
399 conn2.onResponse = (HttpClientResponse ignored) { 408 conn2.onResponse = (HttpClientResponse ignored) {
400 httpClient.shutdown(); 409 httpClient.shutdown();
401 testServerMain.shutdown(); 410 testServerMain.shutdown();
402 }; 411 };
403 }; 412 };
404 }); 413 });
405 testServerMain.start(); 414 testServerMain.start();
406 } 415 }
407 416
417 void testFlush() {
418 TestServerMain testServerMain = new TestServerMain();
419 testServerMain.setServerStartedHandler((int port) {
420 HttpClient httpClient = new HttpClient();
421
422 HttpClientConnection conn = httpClient.get("127.0.0.1", port, "/flush");
423 conn.onRequest = (HttpClientRequest request) {
424 request.outputStream.flush();
425 request.outputStream.close();
426 };
427 conn.onResponse = (HttpClientResponse response) {
428 Expect.equals(HttpStatus.OK, response.statusCode);
429 httpClient.shutdown();
430 testServerMain.shutdown();
431 };
432 });
433 testServerMain.start();
434 }
435
408 void main() { 436 void main() {
409 testHost(); 437 testHost();
410 testExpires(); 438 testExpires();
411 testContentType(); 439 testContentType();
412 testCookies(); 440 testCookies();
441 testFlush();
413 } 442 }
OLDNEW
« no previous file with comments | « runtime/bin/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698