| Index: sdk/lib/_internal/pub/lib/src/barback/admin_server.dart
|
| diff --git a/sdk/lib/_internal/pub/lib/src/barback/admin_server.dart b/sdk/lib/_internal/pub/lib/src/barback/admin_server.dart
|
| index f31d4d2ceb9959eee2f93931de2f51dcb5c637a1..80603b1b22049e9cd8ac96562c9bfe3fc90c6bbd 100644
|
| --- a/sdk/lib/_internal/pub/lib/src/barback/admin_server.dart
|
| +++ b/sdk/lib/_internal/pub/lib/src/barback/admin_server.dart
|
| @@ -7,6 +7,9 @@ library pub.barback.admin_server;
|
| import 'dart:async';
|
| import 'dart:io';
|
|
|
| +import 'package:http_parser/http_parser.dart';
|
| +import 'package:shelf/shelf.dart' as shelf;
|
| +import 'package:shelf_web_socket/shelf_web_socket.dart';
|
| import 'package:stack_trace/stack_trace.dart';
|
|
|
| import '../log.dart' as log;
|
| @@ -19,7 +22,9 @@ import 'web_socket_api.dart';
|
| // See #16954.
|
| class AdminServer extends BaseServer {
|
| /// All currently open [WebSocket] connections.
|
| - final _webSockets = new Set<WebSocket>();
|
| + final _webSockets = new Set<CompatibleWebSocket>();
|
| +
|
| + shelf.Handler _handler;
|
|
|
| /// Creates a new server and binds it to [port] of [host].
|
| static Future<AdminServer> bind(AssetEnvironment environment,
|
| @@ -31,7 +36,11 @@ class AdminServer extends BaseServer {
|
| }
|
|
|
| AdminServer._(AssetEnvironment environment, HttpServer server)
|
| - : super(environment, server);
|
| + : super(environment, server) {
|
| + _handler = new shelf.Cascade()
|
| + .add(webSocketHandler(_handleWebSocket))
|
| + .add(_handleHttp).handler;
|
| + }
|
|
|
| /// Closes the server and all Web Socket connections.
|
| Future close() {
|
| @@ -40,33 +49,23 @@ class AdminServer extends BaseServer {
|
| return Future.wait(futures);
|
| }
|
|
|
| - /// Handles an HTTP request.
|
| - void handleRequest(HttpRequest request) {
|
| - if (WebSocketTransformer.isUpgradeRequest(request)) {
|
| - _handleWebSocket(request);
|
| - return;
|
| - }
|
| + handleRequest(shelf.Request request) => _handler(request);
|
|
|
| + /// Handles an HTTP request.
|
| + _handleHttp(shelf.Request request) {
|
| // TODO(rnystrom): Actually respond to requests once there is an admin
|
| // interface. See #16954.
|
| logRequest(request, "501 Not Implemented");
|
| - request.response.headers.contentType =
|
| - ContentType.parse("text/plain; charset=utf-8");
|
| -
|
| - request.response.statusCode = 501;
|
| - request.response.reasonPhrase = "Not Implemented";
|
| - request.response.write(
|
| - "Currently this server only accepts Web Socket connections.");
|
| - request.response.close();
|
| + return new shelf.Response(501,
|
| + body: "Currently this server only accepts Web Socket connections.");
|
| }
|
|
|
| /// Creates a web socket for [request] which should be an upgrade request.
|
| - void _handleWebSocket(HttpRequest request) {
|
| - Chain.track(WebSocketTransformer.upgrade(request)).then((socket) {
|
| - _webSockets.add(socket);
|
| - var api = new WebSocketApi(socket, environment);
|
| -
|
| - return api.listen().whenComplete(() => _webSockets.remove(api));
|
| - }).catchError(addError);
|
| + void _handleWebSocket(CompatibleWebSocket socket) {
|
| + _webSockets.add(socket);
|
| + var api = new WebSocketApi(socket, environment);
|
| + api.listen()
|
| + .whenComplete(() => _webSockets.remove(api))
|
| + .catchError(addError);
|
| }
|
| }
|
|
|