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

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

Issue 370753002: Fix links of VirtualDirectory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/http_server/pubspec.yaml » ('j') | 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 if (server == null) server = ""; 279 if (server == null) server = "";
280 var footer = 280 var footer =
281 '''</table> 281 '''</table>
282 $server 282 $server
283 </body> 283 </body>
284 </html> 284 </html>
285 '''; 285 ''';
286 286
287 response.write(header); 287 response.write(header);
288 288
289 void add(String name, String modified, var size) { 289 void add(String name, String modified, var size, bool folder) {
290 try {
291 if (size == null) size = "-"; 290 if (size == null) size = "-";
292 if (modified == null) modified = ""; 291 if (modified == null) modified = "";
293 var encodedSize = new HtmlEscape().convert(size.toString()); 292 var encodedSize = new HtmlEscape().convert(size.toString());
294 var encodedModified = new HtmlEscape().convert(modified); 293 var encodedModified = new HtmlEscape().convert(modified);
295 var encodedLink = new HtmlEscape(HtmlEscapeMode.ATTRIBUTE) 294 var encodedLink = new HtmlEscape(HtmlEscapeMode.ATTRIBUTE)
296 .convert(Uri.encodeComponent(normalize(join(path, name)))); 295 .convert(Uri.encodeComponent(name));
296 if (folder) {
297 encodedLink += '/';
298 name += '/';
299 }
297 var encodedName = new HtmlEscape().convert(name); 300 var encodedName = new HtmlEscape().convert(name);
298 301
299 var entry = 302 var entry =
300 ''' <tr> 303 ''' <tr>
301 <td><a href="$encodedLink">$encodedName</a></td> 304 <td><a href="$encodedLink">$encodedName</a></td>
302 <td>$encodedModified</td> 305 <td>$encodedModified</td>
303 <td style="text-align: right">$encodedSize</td> 306 <td style="text-align: right">$encodedSize</td>
304 </tr>'''; 307 </tr>''';
305 response.write(entry); 308 response.write(entry);
306 } catch (e) {
307 print(e);
308 }
309 } 309 }
310 310
311 if (path != '/') { 311 if (path != '/') {
312 add('../', null, null); 312 add('..', null, null, true);
313 } 313 }
314 314
315 dir.list(followLinks: true).listen((entity) { 315 dir.list(followLinks: true).listen((entity) {
316 var name = basename(entity.path);
317 var stat = entity.statSync();
316 if (entity is File) { 318 if (entity is File) {
317 var stat = entity.statSync(); 319 add(name,
318 add(basename(entity.path),
319 stat.modified.toString(), 320 stat.modified.toString(),
320 stat.size); 321 stat.size,
322 false);
321 } else if (entity is Directory) { 323 } else if (entity is Directory) {
322 add(basename(entity.path) + '/', 324 add(name,
323 entity.statSync().modified.toString(), 325 stat.modified.toString(),
324 null); 326 null,
327 true);
325 } 328 }
326 }, onError: (e) { 329 }, onError: (e) {
327 // TODO(kevmoo): log error 330 // TODO(kevmoo): log error
328 }, onDone: () { 331 }, onDone: () {
329 response.write(footer); 332 response.write(footer);
330 response.close(); 333 response.close();
331 }); 334 });
332 }, onError: (e) { 335 }, onError: (e) {
333 // TODO(kevmoo): log error 336 // TODO(kevmoo): log error
334 response.close(); 337 response.close();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 420
418 Future close() => new Future.value(); 421 Future close() => new Future.value();
419 422
420 void setMimeType(List<int> bytes) { 423 void setMimeType(List<int> bytes) {
421 var mimeType = lookupMimeType(path, headerBytes: bytes); 424 var mimeType = lookupMimeType(path, headerBytes: bytes);
422 if (mimeType != null) { 425 if (mimeType != null) {
423 response.headers.contentType = ContentType.parse(mimeType); 426 response.headers.contentType = ContentType.parse(mimeType);
424 } 427 }
425 } 428 }
426 } 429 }
OLDNEW
« no previous file with comments | « no previous file | pkg/http_server/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698