OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library leap_server; | 5 library leap_server; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 class Conversation { | 9 class Conversation { |
10 HttpRequest request; | 10 HttpRequest request; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 64 } |
65 f.openRead().pipe(response).catchError(onError); | 65 f.openRead().pipe(response).catchError(onError); |
66 }); | 66 }); |
67 } | 67 } |
68 | 68 |
69 static onRequest(HttpRequest request) { | 69 static onRequest(HttpRequest request) { |
70 new Conversation(request, request.response).handle(); | 70 new Conversation(request, request.response).handle(); |
71 } | 71 } |
72 | 72 |
73 static onError(error) { | 73 static onError(error) { |
74 if (error is HttpParserException) { | 74 if (error is HttpException) { |
75 print('Error: ${error.message}'); | 75 print('Error: ${error.message}'); |
76 } else { | 76 } else { |
77 print('Error: ${error}'); | 77 print('Error: ${error}'); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 String htmlInfo(String title, String text) { | 81 String htmlInfo(String title, String text) { |
82 return """ | 82 return """ |
83 <!DOCTYPE html> | 83 <!DOCTYPE html> |
84 <html lang='en'> | 84 <html lang='en'> |
(...skipping 23 matching lines...) Expand all Loading... |
108 port = int.parse(arguments[2]); | 108 port = int.parse(arguments[2]); |
109 } | 109 } |
110 HttpServer.bind(host, port).then((HttpServer server) { | 110 HttpServer.bind(host, port).then((HttpServer server) { |
111 print('HTTP server started on http://$host:${server.port}/'); | 111 print('HTTP server started on http://$host:${server.port}/'); |
112 server.listen(Conversation.onRequest, onError: Conversation.onError); | 112 server.listen(Conversation.onRequest, onError: Conversation.onError); |
113 }).catchError((e) { | 113 }).catchError((e) { |
114 print("HttpServer.bind error: $e"); | 114 print("HttpServer.bind error: $e"); |
115 exit(1); | 115 exit(1); |
116 }); | 116 }); |
117 } | 117 } |
OLD | NEW |