| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** |
| 6 * A library for serving HTTP requests and resources. |
| 7 * |
| 8 * ## Installing ## |
| 9 * |
| 10 * Use [pub][] to install this package. Add the following to your |
| 11 * `pubspec.yaml` file. |
| 12 * |
| 13 * dependencies: |
| 14 * http_server: any |
| 15 * |
| 16 * Then run `pub install`. |
| 17 * |
| 18 * For more information, see the |
| 19 * [http_server package on pub.dartlang.org][pub]. |
| 20 * |
| 21 * ## Basic usage |
| 22 * |
| 23 * Here is a short example of how to serve all files from the current |
| 24 * directory. |
| 25 * |
| 26 * import 'dart:io'; |
| 27 * import 'dart:async'; |
| 28 * import 'package:http_server/http_server.dart'; |
| 29 * |
| 30 * void main() { |
| 31 * var staticFiles = new VirtualDirectory('.') |
| 32 * ..allowDirectoryListing = true; |
| 33 * |
| 34 * runZoned(() { |
| 35 * HttpServer.bind('0.0.0.0', 7777).then((server) { |
| 36 * print('Server running'); |
| 37 * server.listen(staticFiles.serveRequest); |
| 38 * }); |
| 39 * }, |
| 40 * onError: (e, stackTrace) => print('Oh noes! $e $stackTrace')); |
| 41 * } |
| 42 * |
| 43 * ## Virtual directory |
| 44 * |
| 45 * The [VirtualDirectory] class makes it easy to serve static content |
| 46 * from the file system. It supports: |
| 47 * |
| 48 * * Range-based requests. |
| 49 * * If-Modified-Since based caching. |
| 50 * * Automatic GZip-compression of content. |
| 51 * * Following symlinks, either throughout the system or inside |
| 52 * a jailed root. |
| 53 * * Directory listing. |
| 54 * |
| 55 * See [VirtualDirectory] for more information. |
| 56 * |
| 57 * ## Virtual host |
| 58 * |
| 59 * The [VirtualHost] class helps to serve multiple hosts on the same |
| 60 * address, by using the `Host` field of the incoming requests. It also |
| 61 * works with wildcards for sub-domains. |
| 62 * |
| 63 * var virtualHost = new VirtualHost(server); |
| 64 * // Filter out on a specific host |
| 65 * var stream1 = virtualServer.addHost('static.myserver.com'); |
| 66 * // Wildcard for any other sub-domains. |
| 67 * var stream2 = virtualServer.addHost('*.myserver.com'); |
| 68 * // Requets not matching any hosts. |
| 69 * var stream3 = virtualServer.unhandled; |
| 70 * |
| 71 * See [VirtualHost] for more information. |
| 72 * |
| 73 * [pub]: http://pub.dartlang.org/packages/http_server |
| 74 */ |
| 5 library http_server; | 75 library http_server; |
| 6 | 76 |
| 7 import 'dart:async'; | 77 import 'dart:async'; |
| 8 import 'dart:convert'; | 78 import 'dart:convert'; |
| 9 import 'dart:io'; | 79 import 'dart:io'; |
| 10 | 80 |
| 11 import 'package:mime/mime.dart'; | 81 import 'package:mime/mime.dart'; |
| 12 import "package:path/path.dart"; | 82 import "package:path/path.dart"; |
| 13 | 83 |
| 14 part 'src/http_body.dart'; | 84 part 'src/http_body.dart'; |
| 15 part 'src/http_body_impl.dart'; | 85 part 'src/http_body_impl.dart'; |
| 16 part 'src/http_multipart_form_data.dart'; | 86 part 'src/http_multipart_form_data.dart'; |
| 17 part 'src/http_multipart_form_data_impl.dart'; | 87 part 'src/http_multipart_form_data_impl.dart'; |
| 18 part 'src/virtual_directory.dart'; | 88 part 'src/virtual_directory.dart'; |
| 19 part 'src/virtual_host.dart'; | 89 part 'src/virtual_host.dart'; |
| 20 | 90 |
| OLD | NEW |