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

Side by Side Diff: test/shelf_io_test.dart

Issue 1037483002: Add support for controlling HttpResponse.bufferOutput to shelf_io. (Closed) Base URL: git@github.com:dart-lang/shelf@master
Patch Set: Code review changes Created 5 years, 9 months 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
« no previous file with comments | « pubspec.yaml ('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) 2014, the Dart project authors. Please see the AUTHORS file 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 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 library shelf_io_test; 5 library shelf_io_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import 'package:http/http.dart' as http; 11 import 'package:http/http.dart' as http;
12 import 'package:http_parser/http_parser.dart' as parser; 12 import 'package:http_parser/http_parser.dart' as parser;
13 import 'package:scheduled_test/scheduled_stream.dart';
13 import 'package:scheduled_test/scheduled_test.dart'; 14 import 'package:scheduled_test/scheduled_test.dart';
14 import 'package:shelf/shelf.dart'; 15 import 'package:shelf/shelf.dart';
15 import 'package:shelf/shelf_io.dart' as shelf_io; 16 import 'package:shelf/shelf_io.dart' as shelf_io;
16 17
17 import 'test_util.dart'; 18 import 'test_util.dart';
18 19
19 void main() { 20 void main() {
20 test('sync handler returns a value to the client', () { 21 test('sync handler returns a value to the client', () {
21 _scheduleServer(syncHandler); 22 _scheduleServer(syncHandler);
22 23
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 _scheduleServer((request) { 325 _scheduleServer((request) {
325 return new Response.ok('test', 326 return new Response.ok('test',
326 headers: {HttpHeaders.SERVER: 'myServer'}); 327 headers: {HttpHeaders.SERVER: 'myServer'});
327 }); 328 });
328 329
329 return _scheduleGet().then((response) { 330 return _scheduleGet().then((response) {
330 expect(response.headers, containsPair(HttpHeaders.SERVER, 'myServer')); 331 expect(response.headers, containsPair(HttpHeaders.SERVER, 'myServer'));
331 }); 332 });
332 }); 333 });
333 }); 334 });
335
336 test('respects the "shelf.io.buffer_output" context parameter', () {
337 var controller = new StreamController();
338 _scheduleServer((request) {
339 controller.add("Hello, ");
340
341 return new Response.ok(UTF8.encoder.bind(controller.stream),
342 context: {"shelf.io.buffer_output": false});
343 });
344
345 schedule(() {
346 var request = new http.Request(
347 "GET", Uri.parse('http://localhost:$_serverPort/'));
348
349 return request.send().then((response) {
350 var stream = new ScheduledStream(UTF8.decoder.bind(response.stream));
351
352 return stream.next().then((data) {
353 expect(data, equals("Hello, "));
354 controller.add("world!");
355 return stream.next();
356 }).then((data) {
357 expect(data, equals("world!"));
358 controller.close();
359 expect(stream.hasNext, completion(isFalse));
360 });
361 });
362 });
363 });
334 } 364 }
335 365
336 int _serverPort; 366 int _serverPort;
337 367
338 Future _scheduleServer(Handler handler) { 368 Future _scheduleServer(Handler handler) {
339 return schedule(() => shelf_io.serve(handler, 'localhost', 0).then((server) { 369 return schedule(() => shelf_io.serve(handler, 'localhost', 0).then((server) {
340 currentSchedule.onComplete.schedule(() { 370 currentSchedule.onComplete.schedule(() {
341 _serverPort = null; 371 _serverPort = null;
342 return server.close(force: true); 372 return server.close(force: true);
343 }); 373 });
(...skipping 14 matching lines...) Expand all
358 return schedule(() { 388 return schedule(() {
359 var request = 389 var request =
360 new http.Request('POST', Uri.parse('http://localhost:$_serverPort/')); 390 new http.Request('POST', Uri.parse('http://localhost:$_serverPort/'));
361 391
362 if (headers != null) request.headers.addAll(headers); 392 if (headers != null) request.headers.addAll(headers);
363 if (body != null) request.body = body; 393 if (body != null) request.body = body;
364 394
365 return request.send(); 395 return request.send();
366 }); 396 });
367 } 397 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698