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('/'), uri);
assert(uri == Path.normalize(uri), uri); //caller's job to avoid HTTP directory traversal
//Defense in depth: refuse RSP source and the server-side `webapp` directory
//here too, so a caller reaching the loader directly can't bypass the
//router/_handle guards. See StreamServer._handle.
if (protectRSP && _reRspSource.hasMatch(uri))
throw Http404(uri: Uri.tryParse(uri));
if (!connect.isForwarded && !connect.isIncluded && reWebapp.hasMatch(uri))
throw Http404(uri: Uri.tryParse(uri));
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]
_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));
}