| 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 part of vmservice_io; | 5 part of vmservice_io; |
| 6 | 6 |
| 7 class WebSocketClient extends Client { | 7 class WebSocketClient extends Client { |
| 8 static const int PARSE_ERROR_CODE = 4000; | 8 static const int PARSE_ERROR_CODE = 4000; |
| 9 static const int BINARY_MESSAGE_ERROR_CODE = 4001; | 9 static const int BINARY_MESSAGE_ERROR_CODE = 4001; |
| 10 static const int NOT_MAP_ERROR_CODE = 4002; | 10 static const int NOT_MAP_ERROR_CODE = 4002; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 final List<String> _allowedOrigins = <String>[]; | 109 final List<String> _allowedOrigins = <String>[]; |
| 110 HttpServer _server; | 110 HttpServer _server; |
| 111 bool get running => _server != null; | 111 bool get running => _server != null; |
| 112 bool _displayMessages = false; | 112 bool _displayMessages = false; |
| 113 | 113 |
| 114 Server(this._service, this._ip, this._port, this._originCheckDisabled) { | 114 Server(this._service, this._ip, this._port, this._originCheckDisabled) { |
| 115 _displayMessages = (_ip != '127.0.0.1' || _port != 8181); | 115 _displayMessages = (_ip != '127.0.0.1' || _port != 8181); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void _addOrigin(String host, String port) { | 118 void _addOrigin(String host, String port) { |
| 119 String origin = 'http://$host:$port'; | 119 if (port == null) { |
| 120 _allowedOrigins.add(origin); | 120 String origin = 'http://$host'; |
| 121 _allowedOrigins.add(origin); |
| 122 } else { |
| 123 String origin = 'http://$host:$port'; |
| 124 _allowedOrigins.add(origin); |
| 125 } |
| 121 } | 126 } |
| 122 | 127 |
| 123 bool _isAllowedOrigin(String origin) { | 128 bool _isAllowedOrigin(String origin) { |
| 124 for (String allowedOrigin in _allowedOrigins) { | 129 for (String allowedOrigin in _allowedOrigins) { |
| 125 if (origin.startsWith(allowedOrigin)) { | 130 if (origin.startsWith(allowedOrigin)) { |
| 126 return true; | 131 return true; |
| 127 } | 132 } |
| 128 } | 133 } |
| 129 return false; | 134 return false; |
| 130 } | 135 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 var address = new InternetAddress(_ip); | 214 var address = new InternetAddress(_ip); |
| 210 // Startup HTTP server. | 215 // Startup HTTP server. |
| 211 return HttpServer.bind(address, _port).then((s) { | 216 return HttpServer.bind(address, _port).then((s) { |
| 212 _server = s; | 217 _server = s; |
| 213 _server.listen(_requestHandler, cancelOnError: true); | 218 _server.listen(_requestHandler, cancelOnError: true); |
| 214 var ip = _server.address.address.toString(); | 219 var ip = _server.address.address.toString(); |
| 215 var port = _server.port.toString(); | 220 var port = _server.port.toString(); |
| 216 // Add the numeric ip and host name to our allowed origins. | 221 // Add the numeric ip and host name to our allowed origins. |
| 217 _addOrigin(ip, port); | 222 _addOrigin(ip, port); |
| 218 _addOrigin(_server.address.host.toString(), port); | 223 _addOrigin(_server.address.host.toString(), port); |
| 219 // Explicitly add localhost and 127.0.0.1. | 224 // Explicitly add localhost and 127.0.0.1 on any port (necessary for |
| 220 _addOrigin('localhost', port); | 225 // adb port forwarding). |
| 221 _addOrigin('127.0.0.1', port); | 226 _addOrigin('127.0.0.1', null); |
| 227 _addOrigin('localhost', null); |
| 222 if (_displayMessages) { | 228 if (_displayMessages) { |
| 223 print('Observatory listening on http://$ip:$port'); | 229 print('Observatory listening on http://$ip:$port'); |
| 224 } | 230 } |
| 225 // Server is up and running. | 231 // Server is up and running. |
| 226 _notifyServerState(ip, _server.port); | 232 _notifyServerState(ip, _server.port); |
| 227 onServerAddressChange('http://$ip:$port'); | 233 onServerAddressChange('http://$ip:$port'); |
| 228 return this; | 234 return this; |
| 229 }).catchError((e, st) { | 235 }).catchError((e, st) { |
| 230 print('Could not start Observatory HTTP server:\n$e\n$st\n'); | 236 print('Could not start Observatory HTTP server:\n$e\n$st\n'); |
| 231 _notifyServerState("", 0); | 237 _notifyServerState("", 0); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 _notifyServerState("", 0); | 273 _notifyServerState("", 0); |
| 268 onServerAddressChange(null); | 274 onServerAddressChange(null); |
| 269 return this; | 275 return this; |
| 270 }); | 276 }); |
| 271 } | 277 } |
| 272 | 278 |
| 273 } | 279 } |
| 274 | 280 |
| 275 void _notifyServerState(String ip, int port) | 281 void _notifyServerState(String ip, int port) |
| 276 native "VMServiceIO_NotifyServerState"; | 282 native "VMServiceIO_NotifyServerState"; |
| OLD | NEW |