| 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:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import 'package:async/async.dart'; |
| 8 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
| 9 import 'package:mime/mime.dart'; | 10 import 'package:mime/mime.dart'; |
| 10 import 'package:path/path.dart' as path; | 11 import 'package:path/path.dart' as path; |
| 11 import 'package:shelf/shelf.dart' as shelf; | 12 import 'package:shelf/shelf.dart' as shelf; |
| 12 import 'package:stack_trace/stack_trace.dart'; | 13 import 'package:stack_trace/stack_trace.dart'; |
| 13 | 14 |
| 14 import '../barback.dart'; | 15 import '../barback.dart'; |
| 15 import '../io.dart'; | 16 import '../io.dart'; |
| 16 import '../log.dart' as log; | 17 import '../log.dart' as log; |
| 17 import '../utils.dart'; | 18 import '../utils.dart'; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // "pub serve" is only used as a development server and doesn't require | 150 // "pub serve" is only used as a development server and doesn't require |
| 150 // any sort of credentials anyway, this is secure. | 151 // any sort of credentials anyway, this is secure. |
| 151 return response.change( | 152 return response.change( |
| 152 headers: const {"Access-Control-Allow-Origin": "*"}); | 153 headers: const {"Access-Control-Allow-Origin": "*"}); |
| 153 }); | 154 }); |
| 154 } | 155 } |
| 155 | 156 |
| 156 /// Returns the body of [asset] as a response to [request]. | 157 /// Returns the body of [asset] as a response to [request]. |
| 157 Future<shelf.Response> _serveAsset(shelf.Request request, Asset asset) async { | 158 Future<shelf.Response> _serveAsset(shelf.Request request, Asset asset) async { |
| 158 try { | 159 try { |
| 159 var pair = tee(await validateStream(asset.read())); | 160 var streams = StreamSplitter.splitFrom( |
| 160 var responseStream = pair.first; | 161 await validateStream(asset.read())); |
| 161 var hashStream = pair.last; | 162 var responseStream = streams.first; |
| 163 var hashStream = streams.last; |
| 162 | 164 |
| 163 // Allow the asset to be cached based on its content hash. | 165 // Allow the asset to be cached based on its content hash. |
| 164 var assetSha = await sha1Stream(hashStream); | 166 var assetSha = await sha1Stream(hashStream); |
| 165 var previousSha = request.headers["if-none-match"]; | 167 var previousSha = request.headers["if-none-match"]; |
| 166 | 168 |
| 167 var headers = { | 169 var headers = { |
| 168 // Enable browser caching of the asset. | 170 // Enable browser caching of the asset. |
| 169 "ETag": assetSha | 171 "ETag": assetSha |
| 170 }; | 172 }; |
| 171 | 173 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 : error = null, | 230 : error = null, |
| 229 isCached = false; | 231 isCached = false; |
| 230 | 232 |
| 231 BarbackServerResult._cached(this.url, this.id) | 233 BarbackServerResult._cached(this.url, this.id) |
| 232 : error = null, | 234 : error = null, |
| 233 isCached = true; | 235 isCached = true; |
| 234 | 236 |
| 235 BarbackServerResult._failure(this.url, this.id, this.error) | 237 BarbackServerResult._failure(this.url, this.id, this.error) |
| 236 : isCached = false; | 238 : isCached = false; |
| 237 } | 239 } |
| OLD | NEW |