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

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

Issue 11035027: Add in-process http server to the dart test scripts. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix runtime test runner as well. Created 8 years, 2 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/test-runtime.dart ('k') | tools/testing/dart/test_progress.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
new file mode 100644
index 0000000000000000000000000000000000000000..fa3b1af8bdfe4862044ebdedd8a7b1e4a1813792
--- /dev/null
+++ b/tools/testing/dart/http_server.dart
@@ -0,0 +1,44 @@
+#library('http_server');
+
+#import('dart:io');
+#import('test_suite.dart'); // For TestUtils.
+
+HttpServer _httpServer;
+
+startHttpServer(String host, int port) {
+ var basePath = TestUtils.dartDir();
+ _httpServer = new HttpServer();
+ _httpServer.listen(host, port);
+ _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) {
+ var requestPath = new Path(request.path).canonicalize();
+ if (!requestPath.isAbsolute) {
+ resp.statusCode = HttpStatus.NOT_FOUND;
+ resp.outputStream.close();
+ } else {
+ var path = basePath;
+ requestPath.segments().forEach((s) => path = path.append(s));
+ var file = new File(path.toNativePath());
+ file.exists().then((exists) {
+ if (exists) {
Søren Gjesse 2012/10/04 10:34:24 How about adding a Content-Type based on the file
Mads Ager (google) 2012/10/04 10:41:42 Yeah, let's add that when we need it. I would like
+ // Allow loading from localhost in browsers.
+ resp.headers.set("Access-Control-Allow-Origin", "*");
+ file.openInputStream().pipe(resp.outputStream);
+ } else {
+ resp.statusCode = HttpStatus.NOT_FOUND;
+ resp.outputStream.close();
+ }
+ });
+ }
+ };
+}
+
+terminateHttpServer() {
+ _httpServer.close();
+}
« no previous file with comments | « tools/test-runtime.dart ('k') | tools/testing/dart/test_progress.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698