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

Side by Side Diff: dart/pkg/http_server/lib/src/virtual_directory.dart

Issue 171363006: pkg/http_server: return a Future on VirtualDirectory.serveFile Base URL: https://github.com/dart-lang/bleeding_edge.git@master
Patch Set: Created 6 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 part of http_server; 5 part of http_server;
6 6
7 7
8 // Used for signal a directory redirecting, where a tailing slash is missing. 8 // Used for signal a directory redirecting, where a tailing slash is missing.
9 class _DirectoryRedirect { 9 class _DirectoryRedirect {
10 const _DirectoryRedirect(); 10 const _DirectoryRedirect();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 * This is usefull when e.g. overriding [directoryHandler] to redirect to 164 * This is usefull when e.g. overriding [directoryHandler] to redirect to
165 * some index file. 165 * some index file.
166 * 166 *
167 * In the request contains the [HttpStatus.IF_MODIFIED_SINCE] header, 167 * In the request contains the [HttpStatus.IF_MODIFIED_SINCE] header,
168 * [serveFile] will send a [HttpStatus.NOT_MODIFIED] response if the file 168 * [serveFile] will send a [HttpStatus.NOT_MODIFIED] response if the file
169 * was not changed. 169 * was not changed.
170 * 170 *
171 * Note that if it was unabled to read from [file], the [request]s response 171 * Note that if it was unabled to read from [file], the [request]s response
172 * is closed with error-code [HttpStatus.NOT_FOUND]. 172 * is closed with error-code [HttpStatus.NOT_FOUND].
173 */ 173 */
174 void serveFile(File file, HttpRequest request) { 174 Future serveFile(File file, HttpRequest request) {
175 var response = request.response; 175 var response = request.response;
176 // TODO(ajohnsen): Set up Zone support for these errors. 176 // TODO(ajohnsen): Set up Zone support for these errors.
177 file.lastModified().then((lastModified) { 177 file.lastModified().then((lastModified) {
178 if (request.headers.ifModifiedSince != null && 178 if (request.headers.ifModifiedSince != null &&
179 !lastModified.isAfter(request.headers.ifModifiedSince)) { 179 !lastModified.isAfter(request.headers.ifModifiedSince)) {
180 response.statusCode = HttpStatus.NOT_MODIFIED; 180 response.statusCode = HttpStatus.NOT_MODIFIED;
181 response.close(); 181 response.close();
182 return null; 182 return null;
183 } 183 }
184 184
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 file.openRead() 231 file.openRead()
232 .pipe(new _VirtualDirectoryFileStream(response, file.path)) 232 .pipe(new _VirtualDirectoryFileStream(response, file.path))
233 .catchError((_) { 233 .catchError((_) {
234 // TODO(kevmoo): log errors 234 // TODO(kevmoo): log errors
235 }); 235 });
236 }); 236 });
237 }).catchError((_) { 237 }).catchError((_) {
238 response.statusCode = HttpStatus.NOT_FOUND; 238 response.statusCode = HttpStatus.NOT_FOUND;
239 response.close(); 239 response.close();
240 }); 240 });
241
242 return response.done;
241 } 243 }
242 244
243 void _serveDirectory(Directory dir, HttpRequest request) { 245 void _serveDirectory(Directory dir, HttpRequest request) {
244 if (_dirCallback != null) { 246 if (_dirCallback != null) {
245 _dirCallback(dir, request); 247 _dirCallback(dir, request);
246 return; 248 return;
247 } 249 }
248 var response = request.response; 250 var response = request.response;
249 dir.stat().then((stats) { 251 dir.stat().then((stats) {
250 if (request.headers.ifModifiedSince != null && 252 if (request.headers.ifModifiedSince != null &&
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 403
402 Future close() => new Future.value(); 404 Future close() => new Future.value();
403 405
404 void setMimeType(List<int> bytes) { 406 void setMimeType(List<int> bytes) {
405 var mimeType = lookupMimeType(path, headerBytes: bytes); 407 var mimeType = lookupMimeType(path, headerBytes: bytes);
406 if (mimeType != null) { 408 if (mimeType != null) {
407 response.headers.contentType = ContentType.parse(mimeType); 409 response.headers.contentType = ContentType.parse(mimeType);
408 } 410 }
409 } 411 }
410 } 412 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698