| 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 part of http_server; | 5 part of http_server; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A [VirtualDirectory] can serve files and directory-listing from a root path, | 8 * A [VirtualDirectory] can serve files and directory-listing from a root path, |
| 9 * to [HttpRequest]s. | 9 * to [HttpRequest]s. |
| 10 * | 10 * |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 if (entity is File) { | 80 if (entity is File) { |
| 81 entity.openRead().pipe(request.response).catchError((_) {}); | 81 entity.openRead().pipe(request.response).catchError((_) {}); |
| 82 } else { | 82 } else { |
| 83 _serveErrorPage(HttpStatus.NOT_FOUND, request); | 83 _serveErrorPage(HttpStatus.NOT_FOUND, request); |
| 84 } | 84 } |
| 85 }); | 85 }); |
| 86 } | 86 } |
| 87 | 87 |
| 88 Future<FileSystemEntity> _locateResource(Path path, | 88 Future<FileSystemEntity> _locateResource(Path path, |
| 89 Iterable<String> segments) { | 89 Iterable<String> segments) { |
| 90 return FileSystemEntity.type(path.toString(), followLinks: false) | 90 return FileSystemEntity.type(path.toNativePath(), followLinks: false) |
| 91 .then((type) { | 91 .then((type) { |
| 92 switch (type) { | 92 switch (type) { |
| 93 case FileSystemEntityType.FILE: | 93 case FileSystemEntityType.FILE: |
| 94 if (segments.isEmpty) return new File.fromPath(path); | 94 if (segments.isEmpty) return new File.fromPath(path); |
| 95 break; | 95 break; |
| 96 | 96 |
| 97 case FileSystemEntityType.DIRECTORY: | 97 case FileSystemEntityType.DIRECTORY: |
| 98 if (segments.isEmpty) { | 98 if (segments.isEmpty) { |
| 99 if (_allowDirectoryListing) return new Directory.fromPath(path); | 99 if (_allowDirectoryListing) return new Directory.fromPath(path); |
| 100 } else { | 100 } else { |
| 101 return _locateResource(path.append(segments.first), | 101 return _locateResource(path.append(segments.first), |
| 102 segments.skip(1)); | 102 segments.skip(1)); |
| 103 } | 103 } |
| 104 break; | 104 break; |
| 105 | 105 |
| 106 case FileSystemEntityType.LINK: | 106 case FileSystemEntityType.LINK: |
| 107 if (followLinks) { | 107 if (followLinks) { |
| 108 // TODO | 108 // TODO |
| 109 } | 109 } |
| 110 break; | 110 break; |
| 111 | |
| 112 } | 111 } |
| 113 // Return `null` on fall-through, to indicate NOT_FOUND. | 112 // Return `null` on fall-through, to indicate NOT_FOUND. |
| 114 return null; | 113 return null; |
| 115 }); | 114 }); |
| 116 } | 115 } |
| 117 | 116 |
| 118 void _serveErrorPage(int error, HttpRequest request) { | 117 void _serveErrorPage(int error, HttpRequest request) { |
| 119 request.response.statusCode = error; | 118 request.response.statusCode = error; |
| 120 request.response.close(); | 119 request.response.close(); |
| 121 } | 120 } |
| 122 } | 121 } |
| OLD | NEW |