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

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

Issue 11800002: "Reverting 16675-16676, 71-73" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 12 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/browser_test.dart ('k') | tools/testing/dart/test_suite.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 56b90ad15375938a1605dcceb81da2efc8594456..8d233a83a0000ed525aa73635bb8b3b26d4d3194 100644
--- a/tools/testing/dart/http_server.dart
+++ b/tools/testing/dart/http_server.dart
@@ -8,17 +8,19 @@ import 'dart:io';
import 'dart:isolate';
import 'test_suite.dart'; // For TestUtils.
-HttpServer startHttpServer(String host, [int allowedPort = -1]) {
+HttpServer _httpServer;
+
+void startHttpServer(String host, int port) {
var basePath = TestUtils.dartDir();
- var httpServer = new HttpServer();
- httpServer.onError = (e) {
+ _httpServer = new HttpServer();
+ _httpServer.onError = (e) {
// Consider errors in the builtin http server fatal.
// Intead of just throwing the exception we print
// a message that makes it clearer what happened.
print('Test http server error: $e');
exit(1);
};
- httpServer.defaultRequestHandler = (request, resp) {
+ _httpServer.defaultRequestHandler = (request, resp) {
var requestPath = new Path(request.path).canonicalize();
if (!requestPath.isAbsolute) {
resp.statusCode = HttpStatus.NOT_FOUND;
@@ -29,23 +31,8 @@ HttpServer startHttpServer(String host, [int allowedPort = -1]) {
var file = new File(path.toNativePath());
file.exists().then((exists) {
if (exists) {
- if (allowedPort != -1) {
- // Allow loading from localhost:$allowedPort in browsers.
- resp.headers.set("Access-Control-Allow-Origin",
- "http://127.0.0.1:$allowedPort");
- resp.headers.set('Access-Control-Allow-Credentials', 'true');
- } else {
- // No allowedPort specified. Allow from anywhere (but cross-origin
- // requests *with credentials* will fail because you can't use "*").
- resp.headers.set("Access-Control-Allow-Origin", "*");
- }
- if (path.toNativePath().endsWith('.html')) {
- resp.headers.set('Content-Type', 'text/html');
- } else if (path.toNativePath().endsWith('.js')) {
- resp.headers.set('Content-Type', 'application/javascript');
- } else if (path.toNativePath().endsWith('.dart')) {
- resp.headers.set('Content-Type', 'application/dart');
- }
+ // Allow loading from localhost in browsers.
+ resp.headers.set("Access-Control-Allow-Origin", "*");
file.openInputStream().pipe(resp.outputStream);
} else {
resp.statusCode = HttpStatus.NOT_FOUND;
@@ -56,16 +43,15 @@ HttpServer startHttpServer(String host, [int allowedPort = -1]) {
};
// Echos back the contents of the request as the response data.
- httpServer.addRequestHandler((req) => req.path == "/echo", (request, resp) {
+ _httpServer.addRequestHandler((req) => req.path == "/echo", (request, resp) {
resp.headers.set("Access-Control-Allow-Origin", "*");
request.inputStream.pipe(resp.outputStream);
});
- httpServer.listen(host, 0);
- return httpServer;
+ _httpServer.listen(host, port);
}
-terminateHttpServers(List<HttpServer> servers) {
- for (var server in servers) server.close();
+terminateHttpServer() {
+ if (_httpServer != null) _httpServer.close();
}
« no previous file with comments | « tools/testing/dart/browser_test.dart ('k') | tools/testing/dart/test_suite.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698