| 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 http_server; | 5 library http_server; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 import 'package:args/args.dart'; | 7 import 'package:args/args.dart'; |
| 8 | 8 |
| 9 /** An options parser for the server. */ | 9 /** An options parser for the server. */ |
| 10 ArgParser getOptionParser() { | 10 ArgParser getOptionParser() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 'csv' : 'text/csv', | 44 'csv' : 'text/csv', |
| 45 'htm' : 'text/html', | 45 'htm' : 'text/html', |
| 46 'html' : 'text/html', | 46 'html' : 'text/html', |
| 47 'txt' : 'text/plain', | 47 'txt' : 'text/plain', |
| 48 'rtf' : 'text/rtf', | 48 'rtf' : 'text/rtf', |
| 49 'mp4' : 'video/mp4', | 49 'mp4' : 'video/mp4', |
| 50 'qt' : 'video/quicktime', | 50 'qt' : 'video/quicktime', |
| 51 'vc1' : 'video/vc1' | 51 'vc1' : 'video/vc1' |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 HttpTestServer(port, this.staticFileDirectory) { | 54 HttpTestServer(int port, this.staticFileDirectory) { |
| 55 server = new HttpServer(); | 55 server = new HttpServer(); |
| 56 server.listen("127.0.0.1", port); | 56 server.listen("127.0.0.1", port); |
| 57 server.onError = (e) { | 57 server.onError = (e) { |
| 58 }; | 58 }; |
| 59 server.defaultRequestHandler = | 59 server.defaultRequestHandler = |
| 60 (HttpRequest request, HttpResponse response) { | 60 (HttpRequest request, HttpResponse response) { |
| 61 try { | 61 try { |
| 62 if (staticFileDirectory != null) { | 62 if (staticFileDirectory != null) { |
| 63 String fname = request.path; | 63 String fname = request.path; |
| 64 String path = '$staticFileDirectory$fname'; | 64 String path = '$staticFileDirectory$fname'; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 93 server.addRequestHandler(matcher, handler); | 93 server.addRequestHandler(matcher, handler); |
| 94 } else { | 94 } else { |
| 95 server.addRequestHandler(matcher, handler.onRequest); | 95 server.addRequestHandler(matcher, handler.onRequest); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 void close() { | 99 void close() { |
| 100 server.close(); | 100 server.close(); |
| 101 } | 101 } |
| 102 } | 102 } |
| OLD | NEW |