Index: runtime/bin/vmservice/server.dart |
diff --git a/runtime/bin/vmservice/server.dart b/runtime/bin/vmservice/server.dart |
index 32ee7d6d24c0c06009b9d6e165b120765d6d477e..3c886cc770be2c24a00a84e1b1b73a49906c5dd9 100644 |
--- a/runtime/bin/vmservice/server.dart |
+++ b/runtime/bin/vmservice/server.dart |
@@ -126,12 +126,19 @@ class Server { |
final bool _originCheckDisabled; |
HttpServer _server; |
bool get running => _server != null; |
- bool _displayMessages = false; |
- Server(this._service, this._ip, this._port, this._originCheckDisabled) { |
- _displayMessages = (_ip != '127.0.0.1' || _port != 8181); |
+ /// 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); |
+ |
bool _isAllowedOrigin(String origin) { |
Uri uri; |
try { |
@@ -231,8 +238,23 @@ class Server { |
return; |
} |
+ final List<String> requestPathSegments = request.uri.pathSegments; |
+ if (requestPathSegments.length < 2) { |
+ // 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[1] == '') ? |
+ ROOT_REDIRECT_PATH : '/${requestPathSegments.sublist(1).join('/')}'; |
if (path == WEBSOCKET_PATH) { |
WebSocketTransformer.upgrade(request).then( |
@@ -274,18 +296,14 @@ 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; |
}); |
@@ -304,24 +322,18 @@ class Server { |
return new Future.value(this); |
} |
- // Force displaying of status messages if we are forcibly shutdown. |
- _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 +341,5 @@ class Server { |
} |
-void _notifyServerState(String ip, int port) |
+void _notifyServerState(String uri) |
native "VMServiceIO_NotifyServerState"; |