OLD | NEW |
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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
10 import "package:crypto/crypto.dart"; | 10 import "package:crypto/crypto.dart"; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // Allow the asset to be cached based on its content hash. | 165 // Allow the asset to be cached based on its content hash. |
166 var sha = new SHA1(); | 166 var sha = new SHA1(); |
167 await hashStream.forEach((chunk) { | 167 await hashStream.forEach((chunk) { |
168 sha.add(chunk); | 168 sha.add(chunk); |
169 }); | 169 }); |
170 | 170 |
171 var assetSha = BASE64.encode(sha.close()); | 171 var assetSha = BASE64.encode(sha.close()); |
172 var previousSha = request.headers["if-none-match"]; | 172 var previousSha = request.headers["if-none-match"]; |
173 | 173 |
174 var headers = { | 174 var headers = { |
175 // Enabled browser caching of the asset. | 175 // Enable browser caching of the asset. |
176 "Cache-Control": "max-age=3600", | |
177 "ETag": assetSha | 176 "ETag": assetSha |
178 }; | 177 }; |
179 | 178 |
180 if (assetSha == previousSha) { | 179 if (assetSha == previousSha) { |
181 // We're requesting an unchanged asset so don't push its body down the | 180 // We're requesting an unchanged asset so don't push its body down the |
182 // wire again. | 181 // wire again. |
183 addResult(new BarbackServerResult._cached(request.url, asset.id)); | 182 addResult(new BarbackServerResult._cached(request.url, asset.id)); |
184 return new shelf.Response.notModified(headers: headers); | 183 return new shelf.Response.notModified(headers: headers); |
185 } else { | 184 } else { |
186 addResult(new BarbackServerResult._success(request.url, asset.id)); | 185 addResult(new BarbackServerResult._success(request.url, asset.id)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 : error = null, | 235 : error = null, |
237 isCached = false; | 236 isCached = false; |
238 | 237 |
239 BarbackServerResult._cached(this.url, this.id) | 238 BarbackServerResult._cached(this.url, this.id) |
240 : error = null, | 239 : error = null, |
241 isCached = true; | 240 isCached = true; |
242 | 241 |
243 BarbackServerResult._failure(this.url, this.id, this.error) | 242 BarbackServerResult._failure(this.url, this.id, this.error) |
244 : isCached = false; | 243 : isCached = false; |
245 } | 244 } |
OLD | NEW |