Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Unified Diff: pkg/http_server/lib/src/virtual_directory.dart

Issue 47513008: Expose 'serveFile' on VirtualDirectory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Expand documentation Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/http_server/test/virtual_directory_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http_server/lib/src/virtual_directory.dart
diff --git a/pkg/http_server/lib/src/virtual_directory.dart b/pkg/http_server/lib/src/virtual_directory.dart
index 4b384668699a1f9276af2e47d7951309f8582ea6..88a9d50cc8fcc46b9f29282e1d723e0c28192801 100644
--- a/pkg/http_server/lib/src/virtual_directory.dart
+++ b/pkg/http_server/lib/src/virtual_directory.dart
@@ -64,7 +64,7 @@ class VirtualDirectory {
return;
}
if (entity is File) {
- _serveFile(entity, request);
+ serveFile(entity, request);
} else if (entity is Directory) {
_serveDirectory(entity, request);
} else {
@@ -141,7 +141,20 @@ class VirtualDirectory {
});
}
- void _serveFile(File file, HttpRequest request) {
+ /**
+ * Serve the content of [file] to [request].
+ *
+ * This is usefull when e.g. overriding [directoryHandler] to redirect to
+ * some index file.
+ *
+ * In the request contains the [HttpStatus.IF_MODIFIED_SINCE] header,
+ * [serveFile] will send a [HttpStatus.NOT_MODIFIED] response if the file
+ * was not changed.
+ *
+ * Note that if it was unabled to read from [file], the [request]s response
+ * is closed with error-code [HttpStatus.NOT_FOUND].
+ */
+ void serveFile(File file, HttpRequest request) {
var response = request.response;
// TODO(ajohnsen): Set up Zone support for these errors.
file.lastModified().then((lastModified) {
@@ -201,6 +214,7 @@ class VirtualDirectory {
.catchError((_) {});
});
}).catchError((_) {
+ response.statusCode = HttpStatus.NOT_FOUND;
response.close();
});
}
« no previous file with comments | « no previous file | pkg/http_server/test/virtual_directory_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698