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

Side by Side Diff: pkg/shelf/test/shelf_io_test.dart

Issue 300023003: pkg/shelf - send Date header in shelf_io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updates Created 6 years, 7 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 | Annotate | Revision Log
« pkg/shelf/CHANGELOG.md ('K') | « pkg/shelf/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:scheduled_test/scheduled_test.dart'; 13 import 'package:scheduled_test/scheduled_test.dart';
13 import 'package:shelf/shelf.dart'; 14 import 'package:shelf/shelf.dart';
14 import 'package:shelf/shelf_io.dart' as shelf_io; 15 import 'package:shelf/shelf_io.dart' as shelf_io;
15 16
16 import 'test_util.dart'; 17 import 'test_util.dart';
17 18
18 void main() { 19 void main() {
19 test('sync handler returns a value to the client', () { 20 test('sync handler returns a value to the client', () {
20 _scheduleServer(syncHandler); 21 _scheduleServer(syncHandler);
21 22
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 return syncHandler(request); 243 return syncHandler(request);
243 }, 'localhost', 0).then((server) { 244 }, 'localhost', 0).then((server) {
244 return http.get('http://localhost:${server.port}').then((response) { 245 return http.get('http://localhost:${server.port}').then((response) {
245 expect(response.statusCode, HttpStatus.OK); 246 expect(response.statusCode, HttpStatus.OK);
246 expect(response.body, 'Hello from /'); 247 expect(response.body, 'Hello from /');
247 server.close(); 248 server.close();
248 }); 249 });
249 }); 250 });
250 }); 251 });
251 }); 252 });
253
254 group('date header', () {
255 test('is sent by default', () {
256 _scheduleServer(syncHandler);
257
258 // update beforeRequest to be one second earlier. Accounts for second
nweiz 2014/05/27 21:06:47 "update" -> "Update" "Accounts for second resolut
kevmoo 2014/05/27 21:10:59 Done.
259 // resolution in HTTP Date.
260 var beforeRequest = new DateTime.now().subtract(new Duration(seconds: 1));
261
262 return _scheduleGet().then((response) {
263 expect(response.headers, contains('date'));
264 var responseDate = parser.parseHttpDate(response.headers['date']);
265
266 expect(responseDate.isAfter(beforeRequest), isTrue);
267 expect(responseDate.isBefore(new DateTime.now()), isTrue);
268 });
269 });
270
271 test('defers to header in response', () {
272 var date = new DateTime.utc(1981, 6, 5);
273 _scheduleServer((request) {
274 return new Response.ok('test', headers: {
275 HttpHeaders.DATE: parser.formatHttpDate(date)
276 });
277 });
278
279 return _scheduleGet().then((response) {
280 expect(response.headers, contains('date'));
281 var responseDate = parser.parseHttpDate(response.headers['date']);
282 expect(responseDate, date);
283 });
284 });
285 });
252 } 286 }
253 287
254 int _serverPort; 288 int _serverPort;
255 289
256 Future _scheduleServer(Handler handler) { 290 Future _scheduleServer(Handler handler) {
257 return schedule(() => shelf_io.serve(handler, 'localhost', 0).then((server) { 291 return schedule(() => shelf_io.serve(handler, 'localhost', 0).then((server) {
258 currentSchedule.onComplete.schedule(() { 292 currentSchedule.onComplete.schedule(() {
259 _serverPort = null; 293 _serverPort = null;
260 return server.close(force: true); 294 return server.close(force: true);
261 }); 295 });
(...skipping 16 matching lines...) Expand all
278 312
279 var request = new http.Request('POST', 313 var request = new http.Request('POST',
280 Uri.parse('http://localhost:$_serverPort/')); 314 Uri.parse('http://localhost:$_serverPort/'));
281 315
282 if (headers != null) request.headers.addAll(headers); 316 if (headers != null) request.headers.addAll(headers);
283 if (body != null) request.body = body; 317 if (body != null) request.body = body;
284 318
285 return request.send(); 319 return request.send();
286 }); 320 });
287 } 321 }
OLDNEW
« pkg/shelf/CHANGELOG.md ('K') | « pkg/shelf/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698