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

Side by Side Diff: tools/testing/dart/http_server.dart

Issue 19486005: test.py: Add 'Cache-Control' header to http responses: enable browsers to cache resources (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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
« no previous file with comments | « no previous file | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 http_server; 5 library http_server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 import 'test_suite.dart'; // For TestUtils. 10 import 'test_suite.dart'; // For TestUtils.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 DebugLogger.info('Server listening on port ${servers.crossOriginPort}'); 81 DebugLogger.info('Server listening on port ${servers.crossOriginPort}');
82 }); 82 });
83 } 83 }
84 } 84 }
85 85
86 /** 86 /**
87 * Runs a set of servers that are initialized specifically for the needs of our 87 * Runs a set of servers that are initialized specifically for the needs of our
88 * test framework, such as dealing with package-root. 88 * test framework, such as dealing with package-root.
89 */ 89 */
90 class TestingServers { 90 class TestingServers {
91 static final _CACHE_EXPIRATION_IN_SECONDS = 30;
91 static final _HARMLESS_REQUEST_PATH_ENDINGS = [ 92 static final _HARMLESS_REQUEST_PATH_ENDINGS = [
92 "/apple-touch-icon.png", 93 "/apple-touch-icon.png",
93 "/apple-touch-icon-precomposed.png", 94 "/apple-touch-icon-precomposed.png",
94 "/favicon.ico", 95 "/favicon.ico",
95 "/foo", 96 "/foo",
96 "/bar", 97 "/bar",
97 "/NonExistingFile", 98 "/NonExistingFile",
98 "/hahaURL", 99 "/hahaURL",
99 ]; 100 ];
100 101
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 onError: (e) { 160 onError: (e) {
160 DebugLogger.error('HttpServer: an error occured', e); 161 DebugLogger.error('HttpServer: an error occured', e);
161 }); 162 });
162 _serverList.add(httpServer); 163 _serverList.add(httpServer);
163 }); 164 });
164 } 165 }
165 166
166 void _handleFileOrDirectoryRequest(HttpRequest request, 167 void _handleFileOrDirectoryRequest(HttpRequest request,
167 HttpResponse response, 168 HttpResponse response,
168 int allowedPort) { 169 int allowedPort) {
170 // Enable browsers to cache file/directory responses.
171 response.headers.set("Cache-Control",
172 "max-age=$_CACHE_EXPIRATION_IN_SECONDS");
169 var path = _getFilePathFromRequestPath(request.uri.path); 173 var path = _getFilePathFromRequestPath(request.uri.path);
170 if (path != null) { 174 if (path != null) {
171 var file = new File.fromPath(path); 175 var file = new File.fromPath(path);
172 file.exists().then((exists) { 176 file.exists().then((exists) {
173 if (exists) { 177 if (exists) {
174 _sendFileContent(request, response, allowedPort, path, file); 178 _sendFileContent(request, response, allowedPort, path, file);
175 } else { 179 } else {
176 var directory = new Directory.fromPath(path); 180 var directory = new Directory.fromPath(path);
177 directory.exists().then((exists) { 181 directory.exists().then((exists) {
178 if (exists) { 182 if (exists) {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 class _Entry { 387 class _Entry {
384 final String name; 388 final String name;
385 final String displayName; 389 final String displayName;
386 390
387 _Entry(this.name, this.displayName); 391 _Entry(this.name, this.displayName);
388 392
389 int compareTo(_Entry other) { 393 int compareTo(_Entry other) {
390 return name.compareTo(other.name); 394 return name.compareTo(other.name);
391 } 395 }
392 } 396 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698