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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samples/leap/leap_script.dart ('k') | samples/leap/request_cache.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/leap/leap_server.dart
===================================================================
--- samples/leap/leap_server.dart (revision 13412)
+++ samples/leap/leap_server.dart (working copy)
@@ -1,74 +0,0 @@
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-#import('dart:io');
-
-class Conversation {
- HttpRequest request;
- HttpResponse response;
-
- static const String LEAP_LANDING_PAGE = 'samples/leap/index.html';
-
- static String landingPage = LEAP_LANDING_PAGE;
-
- Conversation(this.request, this.response);
-
- onClosed() {
- if (response.statusCode == HttpStatus.OK) return;
- print('Request for ${request.path} ${response.statusCode}');
- }
-
- done() {
- response.outputStream.close();
- onClosed();
- }
-
- notFound() {
- response.statusCode = HttpStatus.NOT_FOUND;
- done();
- }
-
- redirect(String location) {
- response.statusCode = HttpStatus.FOUND;
- response.headers.add(HttpHeaders.LOCATION, location);
- done();
- }
-
- handle() {
- String path = request.path;
- if (path == '/') return redirect('/$landingPage');
- if (path == '/favicon.ico') {
- path = '/pkg/dartdoc/static/favicon.ico';
- }
- if (path.contains('..') || path.contains('%')) return notFound();
- var f = new File("./$path");
- f.exists().then((bool exists) {
- if (!exists) return notFound();
- if (path.endsWith('.dart')) {
- response.headers.add(HttpHeaders.CONTENT_TYPE, "application/dart");
- } else if (path.endsWith('.ico')) {
- response.headers.add(HttpHeaders.CONTENT_TYPE, "image/x-icon");
- }
- f.openInputStream().pipe(response.outputStream);
- onClosed();
- });
- }
-
- static onRequest(HttpRequest request, HttpResponse response) {
- new Conversation(request, response).handle();
- }
-}
-
-main() {
- List<String> arguments = new Options().arguments;
- if (arguments.length > 0) {
- Conversation.landingPage = arguments[0];
- }
- var server = new HttpServer();
- var host = '127.0.0.1';
- var port = 8080;
- server.listen(host, port);
- print('HTTP server started on http://$host:$port/');
- server.defaultRequestHandler = Conversation.onRequest;
-}
« 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