load method
Loads the asset of the given URI to the given response.
useCache
- whether to use the cache. If true (default), it will check the cache first, and update the cache if ncessary.
Implementation
@override
Future load(HttpConnect connect, String uri, {bool useCache = true}) async {
assert(uri.startsWith('/'));
assert(uri == Path.normalize(uri)); //caller's job to avoid HTTP directory traversal
var path = uri.substring(1); //uri must start with '/', but path can't
path = Path.join(rootDir, path);
if (rootDir != path && !Path.isWithin(rootDir, path)) {
//Note: this won't happen if caller's does invoke [Path.normalize]
connect.server.logger.severe('$path not in $rootDir', null,
StackTrace.current); //for debugging
throw Http404(uri: Uri.tryParse(uri));
}
final file = File(path);
if (await file.exists())
return loadAsset(connect, FileAsset(file), useCache ? cache: null);
if (await Directory(path).exists())
return _loadFileAt(connect, uri, path, connect.server.indexNames, 0,
useCache ? cache: null);
throw Http404(uri: Uri.tryParse(uri));
}