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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/test-runtime.dart ('k') | tools/testing/dart/test_progress.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #library('http_server');
2
3 #import('dart:io');
4 #import('test_suite.dart'); // For TestUtils.
5
6 HttpServer _httpServer;
7
8 startHttpServer(String host, int port) {
9 var basePath = TestUtils.dartDir();
10 _httpServer = new HttpServer();
11 _httpServer.listen(host, port);
12 _httpServer.onError = (e) {
13 // Consider errors in the builtin http server fatal.
14 // Intead of just throwing the exception we print
15 // a message that makes it clearer what happened.
16 print('Test http server error: $e');
17 exit(1);
18 };
19 _httpServer.defaultRequestHandler = (request, resp) {
20 var requestPath = new Path(request.path).canonicalize();
21 if (!requestPath.isAbsolute) {
22 resp.statusCode = HttpStatus.NOT_FOUND;
23 resp.outputStream.close();
24 } else {
25 var path = basePath;
26 requestPath.segments().forEach((s) => path = path.append(s));
27 var file = new File(path.toNativePath());
28 file.exists().then((exists) {
29 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
30 // Allow loading from localhost in browsers.
31 resp.headers.set("Access-Control-Allow-Origin", "*");
32 file.openInputStream().pipe(resp.outputStream);
33 } else {
34 resp.statusCode = HttpStatus.NOT_FOUND;
35 resp.outputStream.close();
36 }
37 });
38 }
39 };
40 }
41
42 terminateHttpServer() {
43 _httpServer.close();
44 }
OLDNEW
« 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