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

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

Issue 11641005: Add cross-origin test with credentials. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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
Index: tools/testing/dart/http_server.dart
diff --git a/tools/testing/dart/http_server.dart b/tools/testing/dart/http_server.dart
index 8d233a83a0000ed525aa73635bb8b3b26d4d3194..9268cad7a041b2860fcd8ce3d89caa6db0bf17c8 100644
--- a/tools/testing/dart/http_server.dart
+++ b/tools/testing/dart/http_server.dart
@@ -8,19 +8,17 @@ import 'dart:io';
import 'dart:isolate';
import 'test_suite.dart'; // For TestUtils.
-HttpServer _httpServer;
-
-void startHttpServer(String host, int port) {
+HttpServer startHttpServer(String host, int port, int allowedPort) {
var basePath = TestUtils.dartDir();
- _httpServer = new HttpServer();
- _httpServer.onError = (e) {
+ var 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;
@@ -31,8 +29,10 @@ void startHttpServer(String host, int port) {
var file = new File(path.toNativePath());
file.exists().then((exists) {
if (exists) {
- // Allow loading from localhost in browsers.
- resp.headers.set("Access-Control-Allow-Origin", "*");
+ // 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');
file.openInputStream().pipe(resp.outputStream);
} else {
resp.statusCode = HttpStatus.NOT_FOUND;
@@ -43,15 +43,16 @@ void startHttpServer(String host, int port) {
};
// 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, port);
+ httpServer.listen(host, port);
Bill Hesse 2013/01/02 08:22:20 I'm not sure about the whole concept of putting th
Emily Fortuna 2013/01/02 18:22:38 This is no different from what we are currently do
+ return httpServer;
}
-terminateHttpServer() {
- if (_httpServer != null) _httpServer.close();
+terminateHttpServers([List<HttpServer> servers = const []]) {
+ for (var server in servers) server.close();
}

Powered by Google App Engine
This is Rietveld 408576698