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

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

Issue 360453004: Use utf-8 encoding for listing and error page, in http_server VirtualDirectory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update right pubspec... 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 247 }
248 var response = request.response; 248 var response = request.response;
249 dir.stat().then((stats) { 249 dir.stat().then((stats) {
250 if (request.headers.ifModifiedSince != null && 250 if (request.headers.ifModifiedSince != null &&
251 !stats.modified.isAfter(request.headers.ifModifiedSince)) { 251 !stats.modified.isAfter(request.headers.ifModifiedSince)) {
252 response.statusCode = HttpStatus.NOT_MODIFIED; 252 response.statusCode = HttpStatus.NOT_MODIFIED;
253 response.close(); 253 response.close();
254 return; 254 return;
255 } 255 }
256 256
257 response.headers.contentType =
258 new ContentType('text', 'html', parameters: {'charset': 'utf-8'});
257 response.headers.set(HttpHeaders.LAST_MODIFIED, stats.modified); 259 response.headers.set(HttpHeaders.LAST_MODIFIED, stats.modified);
258 var path = Uri.decodeComponent(request.uri.path); 260 var path = Uri.decodeComponent(request.uri.path);
259 var encodedPath = new HtmlEscape().convert(path); 261 var encodedPath = new HtmlEscape().convert(path);
260 var header = 262 var header =
261 '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 263 '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
262 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 264 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
263 <html xmlns="http://www.w3.org/1999/xhtml"> 265 <html xmlns="http://www.w3.org/1999/xhtml">
264 <head> 266 <head>
265 <title>Index of $encodedPath</title> 267 <title>Index of $encodedPath</title>
266 </head> 268 </head>
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 }); 335 });
334 } 336 }
335 337
336 void _serveErrorPage(int error, HttpRequest request) { 338 void _serveErrorPage(int error, HttpRequest request) {
337 var response = request.response; 339 var response = request.response;
338 response.statusCode = error; 340 response.statusCode = error;
339 if (_errorCallback != null) { 341 if (_errorCallback != null) {
340 _errorCallback(request); 342 _errorCallback(request);
341 return; 343 return;
342 } 344 }
345 response.headers.contentType =
346 new ContentType('text', 'html', parameters: {'charset': 'utf-8'});
343 // Default error page. 347 // Default error page.
344 var path = Uri.decodeComponent(request.uri.path); 348 var path = Uri.decodeComponent(request.uri.path);
345 var encodedPath = new HtmlEscape().convert(path); 349 var encodedPath = new HtmlEscape().convert(path);
346 var encodedReason = new HtmlEscape().convert(response.reasonPhrase); 350 var encodedReason = new HtmlEscape().convert(response.reasonPhrase);
347 var encodedError = new HtmlEscape().convert(error.toString()); 351 var encodedError = new HtmlEscape().convert(error.toString());
348 352
349 var server = response.headers.value(HttpHeaders.SERVER); 353 var server = response.headers.value(HttpHeaders.SERVER);
350 if (server == null) server = ""; 354 if (server == null) server = "";
351 var page = 355 var page =
352 '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 356 '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 417
414 Future close() => new Future.value(); 418 Future close() => new Future.value();
415 419
416 void setMimeType(List<int> bytes) { 420 void setMimeType(List<int> bytes) {
417 var mimeType = lookupMimeType(path, headerBytes: bytes); 421 var mimeType = lookupMimeType(path, headerBytes: bytes);
418 if (mimeType != null) { 422 if (mimeType != null) {
419 response.headers.contentType = ContentType.parse(mimeType); 423 response.headers.contentType = ContentType.parse(mimeType);
420 } 424 }
421 } 425 }
422 } 426 }
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