OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Command line tool to run the checker on a Dart program. | 5 /// Command line tool to run the checker on a Dart program. |
6 library dev_compiler.devc; | 6 library dev_compiler.devc; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 } | 283 } |
284 | 284 |
285 shelf.Handler rebuildAndCache(shelf.Handler handler) => (request) { | 285 shelf.Handler rebuildAndCache(shelf.Handler handler) => (request) { |
286 _log.fine('requested $GREEN_COLOR${request.url}$NO_COLOR'); | 286 _log.fine('requested $GREEN_COLOR${request.url}$NO_COLOR'); |
287 // Trigger recompile only when requesting the HTML page. | 287 // Trigger recompile only when requesting the HTML page. |
288 var segments = request.url.pathSegments; | 288 var segments = request.url.pathSegments; |
289 bool isEntryPage = segments.length == 0 || segments[0] == _entryPath; | 289 bool isEntryPage = segments.length == 0 || segments[0] == _entryPath; |
290 if (isEntryPage) compiler._runAgain(); | 290 if (isEntryPage) compiler._runAgain(); |
291 | 291 |
292 // To help browsers cache resources that don't change, we serve these | 292 // To help browsers cache resources that don't change, we serve these |
293 // resources under a path containing their hash: | 293 // resources by adding a query parameter containing their hash: |
294 // /cached/{hash}/{path-to-file.js} | 294 // /{path-to-file.js}?____cached={hash} |
295 bool isCached = segments.length > 1 && segments[0] == 'cached'; | 295 var hash = request.url.queryParameters['____cached']; |
296 if (isCached) { | |
297 // Changing the request lets us record that the hash prefix is handled | |
298 // here, and that the underlying handler should use the rest of the url to | |
299 // determine where to find the resource in the file system. | |
300 request = request.change(path: path.join('cached', segments[1])); | |
301 } | |
302 var response = handler(request); | 296 var response = handler(request); |
303 var policy = isCached ? 'max-age=${24 * 60 * 60}' : 'no-cache'; | 297 var policy = hash != null ? 'max-age=${24 * 60 * 60}' : 'no-cache'; |
304 var headers = {'cache-control': policy}; | 298 var headers = {'cache-control': policy}; |
305 if (isCached) { | 299 if (hash != null) { |
306 // Note: the cache-control header should be enough, but this doesn't hurt | 300 // Note: the cache-control header should be enough, but this doesn't hurt |
307 // and can help renew the policy after it expires. | 301 // and can help renew the policy after it expires. |
308 headers['ETag'] = segments[1]; | 302 headers['ETag'] = hash; |
309 } | 303 } |
310 return response.change(headers: headers); | 304 return response.change(headers: headers); |
311 }; | 305 }; |
312 } | 306 } |
313 | 307 |
314 final _log = new Logger('dev_compiler'); | 308 final _log = new Logger('dev_compiler'); |
315 final _earlyErrorResult = new CheckerResults(const [], null, true); | 309 final _earlyErrorResult = new CheckerResults(const [], null, true); |
OLD | NEW |