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

Side by Side Diff: samples/leap/leap_server.dart

Issue 11085017: Move leap to lib/compiler/samples. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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 | « samples/leap/leap_script.dart ('k') | samples/leap/request_cache.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 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #import('dart:io');
6
7 class Conversation {
8 HttpRequest request;
9 HttpResponse response;
10
11 static const String LEAP_LANDING_PAGE = 'samples/leap/index.html';
12
13 static String landingPage = LEAP_LANDING_PAGE;
14
15 Conversation(this.request, this.response);
16
17 onClosed() {
18 if (response.statusCode == HttpStatus.OK) return;
19 print('Request for ${request.path} ${response.statusCode}');
20 }
21
22 done() {
23 response.outputStream.close();
24 onClosed();
25 }
26
27 notFound() {
28 response.statusCode = HttpStatus.NOT_FOUND;
29 done();
30 }
31
32 redirect(String location) {
33 response.statusCode = HttpStatus.FOUND;
34 response.headers.add(HttpHeaders.LOCATION, location);
35 done();
36 }
37
38 handle() {
39 String path = request.path;
40 if (path == '/') return redirect('/$landingPage');
41 if (path == '/favicon.ico') {
42 path = '/pkg/dartdoc/static/favicon.ico';
43 }
44 if (path.contains('..') || path.contains('%')) return notFound();
45 var f = new File("./$path");
46 f.exists().then((bool exists) {
47 if (!exists) return notFound();
48 if (path.endsWith('.dart')) {
49 response.headers.add(HttpHeaders.CONTENT_TYPE, "application/dart");
50 } else if (path.endsWith('.ico')) {
51 response.headers.add(HttpHeaders.CONTENT_TYPE, "image/x-icon");
52 }
53 f.openInputStream().pipe(response.outputStream);
54 onClosed();
55 });
56 }
57
58 static onRequest(HttpRequest request, HttpResponse response) {
59 new Conversation(request, response).handle();
60 }
61 }
62
63 main() {
64 List<String> arguments = new Options().arguments;
65 if (arguments.length > 0) {
66 Conversation.landingPage = arguments[0];
67 }
68 var server = new HttpServer();
69 var host = '127.0.0.1';
70 var port = 8080;
71 server.listen(host, port);
72 print('HTTP server started on http://$host:$port/');
73 server.defaultRequestHandler = Conversation.onRequest;
74 }
OLDNEW
« no previous file with comments | « samples/leap/leap_script.dart ('k') | samples/leap/request_cache.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698