From bb2f54bb91f858d11a0d632187c777dab6e25f99 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 23 Jul 2015 19:51:03 -0700 Subject: [PATCH] Use shelf instead of http_server This patch switches sky_server.dart to use shelf rather than http_server. --- packages/flutter_tools/bin/sky_server.dart | 18 +++++++----------- packages/flutter_tools/pubspec.yaml | 3 ++- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/flutter_tools/bin/sky_server.dart b/packages/flutter_tools/bin/sky_server.dart index 7308257fca..e84a949d2a 100644 --- a/packages/flutter_tools/bin/sky_server.dart +++ b/packages/flutter_tools/bin/sky_server.dart @@ -2,10 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:async'; import 'dart:io'; -import 'package:http_server/http_server.dart'; +import 'package:shelf_static/shelf_static.dart'; +import 'package:shelf/shelf_io.dart' as io; +import 'package:shelf/shelf.dart'; const String usage = 'Usage: sky_server PORT'; @@ -23,26 +24,21 @@ main(List argv) async { return; } - VirtualDirectory currentDirectory = new VirtualDirectory('.') - ..followLinks = true - ..jailRoot = false - ..allowDirectoryListing = true; + Handler handler = createStaticHandler(Directory.current.path, + serveFilesOutsidePath: true); HttpServer server; try { - server = await HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port); + server = await io.serve(handler, InternetAddress.LOOPBACK_IP_V4, port); } catch(e) { print(e); return; } + server.autoCompress = true; server.defaultResponseHeaders ..removeAll('x-content-type-options') ..removeAll('x-frame-options') ..removeAll('x-xss-protection') ..add('cache-control', 'no-cache'); - - server - ..autoCompress = true - ..listen(currentDirectory.serveRequest); } diff --git a/packages/flutter_tools/pubspec.yaml b/packages/flutter_tools/pubspec.yaml index a8a5c00589..ee1042ba1d 100644 --- a/packages/flutter_tools/pubspec.yaml +++ b/packages/flutter_tools/pubspec.yaml @@ -1,7 +1,8 @@ author: Chromium Authors dependencies: args: ^0.13.0 - http_server: ^0.9.5 + shelf: ^0.6.2 + shelf_static: ^0.2.2 description: Tools for building Sky applications environment: sdk: ">=1.8.0 <2.0.0"