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

Unified Diff: tools/testing/dart/http_server.dart

Issue 12559013: Revert "Update the test runner to use the new dart:io API" again (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 | « tools/testing/dart/co19_test.dart ('k') | tools/testing/dart/multitest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/testing/dart/http_server.dart
diff --git a/tools/testing/dart/http_server.dart b/tools/testing/dart/http_server.dart
index f1f108853623608411c2b477d11dfebbb0848650..d065e0bcaac33f64a9dda61127ccee40c4d58c7f 100644
--- a/tools/testing/dart/http_server.dart
+++ b/tools/testing/dart/http_server.dart
@@ -1,4 +1,4 @@
-// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -101,12 +101,11 @@ class TestingServers {
* "Access-Control-Allow-Origin: client:port1
* "Access-Control-Allow-Credentials: true"
*/
- Future startServers(String host, {int port: 0, int crossOriginPort: 0}) {
- return _startHttpServer(host, port: port).then((_) {
- _startHttpServer(host,
- port: crossOriginPort,
- allowedPort:_serverList[0].port);
- });
+ void startServers(String host, {int port: 0, int crossOriginPort: 0}) {
+ _startHttpServer(host, port: port);
+ _startHttpServer(host,
+ port: crossOriginPort,
+ allowedPort:_serverList[0].port);
}
String httpServerCommandline() {
@@ -126,27 +125,25 @@ class TestingServers {
}
}
- Future _startHttpServer(String host, {int port: 0, int allowedPort: -1}) {
- return HttpServer.bind(host, port).then((HttpServer httpServer) {
- httpServer.listen((HttpRequest request) {
- if (request.uri.path == "/echo") {
- _handleEchoRequest(request, request.response);
- } else {
- _handleFileOrDirectoryRequest(
- request, request.response, allowedPort);
- }
- },
- onError: (e) {
- DebugLogger.error('HttpServer: an error occured: $e');
- });
- _serverList.add(httpServer);
- });
+ void _startHttpServer(String host, {int port: 0, int allowedPort: -1}) {
+ var httpServer = new HttpServer();
+ httpServer.onError = (e) {
+ DebugLogger.error('HttpServer: an error occured: $e');
+ };
+ httpServer.defaultRequestHandler = (request, response) {
+ _handleFileOrDirectoryRequest(request, response, allowedPort);
+ };
+ httpServer.addRequestHandler(
+ (req) => req.path == "/echo", _handleEchoRequest);
+
+ httpServer.listen(host, port);
+ _serverList.add(httpServer);
}
void _handleFileOrDirectoryRequest(HttpRequest request,
HttpResponse response,
int allowedPort) {
- var path = _getFilePathFromRequestPath(request.uri.path);
+ var path = _getFilePathFromRequestPath(request.path);
if (path != null) {
var file = new File.fromPath(path);
file.exists().then((exists) {
@@ -166,7 +163,7 @@ class TestingServers {
}
});
} else {
- if (request.uri.path == '/') {
+ if (request.path == '/') {
var entries = [new _Entry('root_dart', 'root_dart/'),
new _Entry('root_build', 'root_build/'),
new _Entry('echo', 'echo')];
@@ -179,11 +176,7 @@ class TestingServers {
void _handleEchoRequest(HttpRequest request, HttpResponse response) {
response.headers.set("Access-Control-Allow-Origin", "*");
- request.pipe(response);
- response.done.catchError((e) {
- DebugLogger.warning(
- 'HttpServer: error while closing the response stream: $e');
- });
+ request.inputStream.pipe(response.outputStream);
}
Path _getFilePathFromRequestPath(String urlRequestPath) {
@@ -222,18 +215,18 @@ class TestingServers {
var completer = new Completer();
var entries = [];
- directory.list().listen(
- (FileSystemEntity fse) {
- var filename = new Path(fse.path).filename;
- if (fse is File) {
- entries.add(new _Entry(filename, filename));
- } else if (fse is Directory) {
- entries.add(new _Entry(filename, '$filename/'));
- }
- },
- onDone: () {
+ directory.list()
+ ..onFile = (filepath) {
+ var filename = new Path(filepath).filename;
+ entries.add(new _Entry(filename, filename));
+ }
+ ..onDir = (dirpath) {
+ var filename = new Path(dirpath).filename;
+ entries.add(new _Entry(filename, '$filename/'));
+ }
+ ..onDone = (_) {
completer.complete(entries);
- });
+ };
return completer.future;
}
@@ -244,11 +237,11 @@ class TestingServers {
var header = '''<!DOCTYPE html>
<html>
<head>
- <title>${request.uri.path}</title>
+ <title>${request.path}</title>
</head>
<body>
<code>
- <div>${request.uri.path}</div>
+ <div>${request.path}</div>
<hr/>
<ul>''';
var footer = '''
@@ -259,18 +252,14 @@ class TestingServers {
entries.sort();
- response.write(header);
+ response.outputStream.writeString(header);
for (var entry in entries) {
- response.write(
- '<li><a href="${new Path(request.uri.path).append(entry.name)}">'
+ response.outputStream.writeString(
+ '<li><a href="${new Path(request.path).append(entry.name)}">'
'${entry.displayName}</a></li>');
}
- response.write(footer);
- response.close();
- response.done.catchError((e) {
- DebugLogger.warning(
- 'HttpServer: error while closing the response stream: $e');
- });
+ response.outputStream.writeString(footer);
+ response.outputStream.close();
}
void _sendFileContent(HttpRequest request,
@@ -307,27 +296,26 @@ class TestingServers {
} else if (path.filename.endsWith('.dart')) {
response.headers.set('Content-Type', 'application/dart');
}
- file.openRead().pipe(response);
- response.done.catchError((e) {
- DebugLogger.warning(
- 'HttpServer: error while closing the response stream: $e');
- });
+ file.openInputStream().pipe(response.outputStream);
}
void _sendNotFound(HttpRequest request, HttpResponse response) {
// NOTE: Since some tests deliberately try to access non-existent files.
// We might want to remove this warning (otherwise it will show
// up in the debug.log every time).
- if (request.uri.path != "/favicon.ico") {
- DebugLogger.warning('HttpServer: could not find file for request path: '
- '"${request.uri.path}"');
- }
+ DebugLogger.warning('HttpServer: could not find file for request path: '
+ '"${request.path}"');
response.statusCode = HttpStatus.NOT_FOUND;
- response.close();
- response.done.catchError((e) {
- DebugLogger.warning(
- 'HttpServer: error while closing the response stream: $e');
- });
+ try {
+ response.outputStream.close();
+ } catch (e) {
+ if (e is StreamException) {
+ DebugLogger.warning('HttpServer: error while closing the response '
+ 'stream: $e');
+ } else {
+ throw e;
+ }
+ }
}
}
« no previous file with comments | « tools/testing/dart/co19_test.dart ('k') | tools/testing/dart/multitest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698