| 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 library pub.barback.server; | 5 library pub.barback.server; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 return notFound(request, error: ex.message); | 94 return notFound(request, error: ex.message); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // See if the asset should be blocked. | 97 // See if the asset should be blocked. |
| 98 if (allowAsset != null && !allowAsset(id)) { | 98 if (allowAsset != null && !allowAsset(id)) { |
| 99 return notFound(request, | 99 return notFound(request, |
| 100 error: "Asset $id is not available in this configuration.", | 100 error: "Asset $id is not available in this configuration.", |
| 101 asset: id); | 101 asset: id); |
| 102 } | 102 } |
| 103 | 103 |
| 104 logRequest(request, "Loading $id"); | |
| 105 return environment.barback.getAssetById(id).then((result) { | 104 return environment.barback.getAssetById(id).then((result) { |
| 106 logRequest(request, "getAssetById($id) returned"); | |
| 107 return result; | 105 return result; |
| 108 }).then((asset) => _serveAsset(request, asset)).catchError((error, trace) { | 106 }).then((asset) => _serveAsset(request, asset)).catchError((error, trace) { |
| 109 if (error is! AssetNotFoundException) throw error; | 107 if (error is! AssetNotFoundException) throw error; |
| 110 return environment.barback.getAssetById(id.addExtension("/index.html")) | 108 return environment.barback.getAssetById(id.addExtension("/index.html")) |
| 111 .then((asset) { | 109 .then((asset) { |
| 112 if (request.url.path.endsWith('/')) return _serveAsset(request, asset); | 110 if (request.url.path.endsWith('/')) return _serveAsset(request, asset); |
| 113 | 111 |
| 114 // We only want to serve index.html if the URL explicitly ends in a | 112 // We only want to serve index.html if the URL explicitly ends in a |
| 115 // slash. For other URLs, we redirect to one with the slash added to | 113 // slash. For other URLs, we redirect to one with the slash added to |
| 116 // implicitly support that too. This follows Apache's behavior. | 114 // implicitly support that too. This follows Apache's behavior. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 bool get isSuccess => error == null; | 181 bool get isSuccess => error == null; |
| 184 | 182 |
| 185 /// Whether the request was served unsuccessfully. | 183 /// Whether the request was served unsuccessfully. |
| 186 bool get isFailure => !isSuccess; | 184 bool get isFailure => !isSuccess; |
| 187 | 185 |
| 188 BarbackServerResult._success(this.url, this.id) | 186 BarbackServerResult._success(this.url, this.id) |
| 189 : error = null; | 187 : error = null; |
| 190 | 188 |
| 191 BarbackServerResult._failure(this.url, this.id, this.error); | 189 BarbackServerResult._failure(this.url, this.id, this.error); |
| 192 } | 190 } |
| OLD | NEW |