| Index: runtime/bin/vmservice/server.dart
|
| diff --git a/runtime/bin/vmservice/server.dart b/runtime/bin/vmservice/server.dart
|
| index 32ee7d6d24c0c06009b9d6e165b120765d6d477e..84b39566d2bc088e952eb432663d2220f43e5d11 100644
|
| --- a/runtime/bin/vmservice/server.dart
|
| +++ b/runtime/bin/vmservice/server.dart
|
| @@ -128,6 +128,16 @@ class Server {
|
| bool get running => _server != null;
|
| bool _displayMessages = false;
|
|
|
| + /// Returns the server address including the auth token.
|
| + Uri get serverAddress {
|
| + if (!running) {
|
| + return null;
|
| + }
|
| + var ip = _server.address.address;
|
| + var port = _server.port;
|
| + return Uri.parse('http://$ip:$port/$serviceAuthToken/');
|
| + }
|
| +
|
| Server(this._service, this._ip, this._port, this._originCheckDisabled) {
|
| _displayMessages = (_ip != '127.0.0.1' || _port != 8181);
|
| }
|
| @@ -231,8 +241,23 @@ class Server {
|
| return;
|
| }
|
|
|
| + final List<String> requestPathSegments = request.uri.pathSegments;
|
| + if (requestPathSegments.length < 1) {
|
| + // Malformed.
|
| + request.response.close();
|
| + return;
|
| + }
|
| + // Check that we were given the auth token.
|
| + final String authToken = requestPathSegments[0];
|
| + if (authToken != serviceAuthToken) {
|
| + // Malformed.
|
| + request.response.close();
|
| + return;
|
| + }
|
| + // Construct the actual request path by chopping off the auth token.
|
| final String path =
|
| - request.uri.path == '/' ? ROOT_REDIRECT_PATH : request.uri.path;
|
| + (requestPathSegments.length == 1) ?
|
| + ROOT_REDIRECT_PATH : '/${requestPathSegments.sublist(1).join('/')}';
|
|
|
| if (path == WEBSOCKET_PATH) {
|
| WebSocketTransformer.upgrade(request).then(
|
| @@ -274,18 +299,16 @@ class Server {
|
| return HttpServer.bind(address, _port).then((s) {
|
| _server = s;
|
| _server.listen(_requestHandler, cancelOnError: true);
|
| - var ip = _server.address.address;
|
| - var port = _server.port;
|
| if (_displayMessages) {
|
| - print('Observatory listening on http://$ip:$port');
|
| + print('Observatory listening on $serverAddress');
|
| }
|
| // Server is up and running.
|
| - _notifyServerState(ip, _server.port);
|
| - onServerAddressChange('http://$ip:$port');
|
| + _notifyServerState(serverAddress.toString());
|
| + onServerAddressChange('$serverAddress');
|
| return this;
|
| }).catchError((e, st) {
|
| print('Could not start Observatory HTTP server:\n$e\n$st\n');
|
| - _notifyServerState("", 0);
|
| + _notifyServerState("");
|
| onServerAddressChange(null);
|
| return this;
|
| });
|
| @@ -308,20 +331,19 @@ class Server {
|
| _displayMessages = _displayMessages || forced;
|
|
|
| // Shutdown HTTP server and subscription.
|
| - var ip = _server.address.address.toString();
|
| - var port = _server.port.toString();
|
| + String oldServerAddress = serverAddress;
|
| return cleanup(forced).then((_) {
|
| if (_displayMessages) {
|
| - print('Observatory no longer listening on http://$ip:$port');
|
| + print('Observatory no longer listening on $oldServerAddress');
|
| }
|
| _server = null;
|
| - _notifyServerState("", 0);
|
| + _notifyServerState("");
|
| onServerAddressChange(null);
|
| return this;
|
| }).catchError((e, st) {
|
| _server = null;
|
| print('Could not shutdown Observatory HTTP server:\n$e\n$st\n');
|
| - _notifyServerState("", 0);
|
| + _notifyServerState("");
|
| onServerAddressChange(null);
|
| return this;
|
| });
|
| @@ -329,5 +351,5 @@ class Server {
|
|
|
| }
|
|
|
| -void _notifyServerState(String ip, int port)
|
| +void _notifyServerState(String uri)
|
| native "VMServiceIO_NotifyServerState";
|
|
|