Chromium Code Reviews| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 bool get running => _server != null; | 128 bool get running => _server != null; |
| 129 | 129 |
| 130 /// Returns the server address including the auth token. | 130 /// Returns the server address including the auth token. |
| 131 Uri get serverAddress { | 131 Uri get serverAddress { |
| 132 if (!running) { | 132 if (!running) { |
| 133 return null; | 133 return null; |
| 134 } | 134 } |
| 135 var ip = _server.address.address; | 135 var ip = _server.address.address; |
| 136 var port = _server.port; | 136 var port = _server.port; |
| 137 if (useAuthToken) { | 137 if (useAuthToken) { |
| 138 return Uri.parse('http://$ip:$port/$serviceAuthToken/'); | 138 return new Uri(scheme: 'http', host: ip, port: port, |
| 139 path: serviceAuthToken); | |
| 139 } else { | 140 } else { |
| 140 return Uri.parse('http://$ip:$port/'); | 141 return new Uri(scheme: 'http', host: ip, port: port); |
| 141 } | 142 } |
| 142 } | 143 } |
| 143 | 144 |
| 144 Server(this._service, this._ip, this._port, this._originCheckDisabled); | 145 Server(this._service, this._ip, this._port, this._originCheckDisabled); |
| 145 | 146 |
| 146 bool _isAllowedOrigin(String origin) { | 147 bool _isAllowedOrigin(String origin) { |
| 147 Uri uri; | 148 Uri uri; |
| 148 try { | 149 try { |
| 149 uri = Uri.parse(origin); | 150 uri = Uri.parse(origin); |
| 150 } catch (_) { | 151 } catch (_) { |
| 151 return false; | 152 return false; |
| 152 } | 153 } |
| 153 | 154 |
| 154 // Explicitly add localhost and 127.0.0.1 on any port (necessary for | 155 // Explicitly add localhost and 127.0.0.1 on any port (necessary for |
| 155 // adb port forwarding). | 156 // adb port forwarding). |
| 156 if ((uri.host == 'localhost') || | 157 if ((uri.host == 'localhost') || |
| 158 (uri.host == '::1') || | |
| 157 (uri.host == '127.0.0.1')) { | 159 (uri.host == '127.0.0.1')) { |
| 158 return true; | 160 return true; |
| 159 } | 161 } |
| 160 | 162 |
| 161 if ((uri.port == _server.port) && | 163 if ((uri.port == _server.port) && |
| 162 ((uri.host == _server.address.address) || | 164 ((uri.host == _server.address.address) || |
| 163 (uri.host == _server.address.host))) { | 165 (uri.host == _server.address.host))) { |
| 164 return true; | 166 return true; |
| 165 } | 167 } |
| 166 | 168 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 var client = new HttpRequestClient(request, _service); | 295 var client = new HttpRequestClient(request, _service); |
| 294 var message = new Message.fromUri(client, request.uri); | 296 var message = new Message.fromUri(client, request.uri); |
| 295 client.onMessage(null, message); | 297 client.onMessage(null, message); |
| 296 } catch (e) { | 298 } catch (e) { |
| 297 print('Unexpected error processing HTTP request uri: ' | 299 print('Unexpected error processing HTTP request uri: ' |
| 298 '${request.uri}\n$e\n'); | 300 '${request.uri}\n$e\n'); |
| 299 rethrow; | 301 rethrow; |
| 300 } | 302 } |
| 301 } | 303 } |
| 302 | 304 |
| 303 Future startup() { | 305 Future startup() async { |
| 304 if (_server != null) { | 306 if (_server != null) { |
| 305 // Already running. | 307 // Already running. |
| 306 return new Future.value(this); | 308 return this; |
| 307 } | 309 } |
| 308 | 310 |
| 309 var address = new InternetAddress(_ip); | |
| 310 // Startup HTTP server. | 311 // Startup HTTP server. |
| 311 return HttpServer.bind(address, _port).then((s) { | 312 try { |
| 312 _server = s; | 313 var address = (await InternetAddress.lookup(_ip))[0]; |
|
rmacnak
2016/11/18 23:50:33
On my workstation, the IPv6 result comes back firs
Cutch
2016/11/19 22:21:37
This code should stay consistent with the existing
rmacnak
2016/11/22 04:00:52
Done.
| |
| 314 _server = await HttpServer.bind(address, _port); | |
| 313 _server.listen(_requestHandler, cancelOnError: true); | 315 _server.listen(_requestHandler, cancelOnError: true); |
| 314 print('Observatory listening on $serverAddress'); | 316 print('Observatory listening on $serverAddress'); |
| 315 // Server is up and running. | 317 // Server is up and running. |
| 316 _notifyServerState(serverAddress.toString()); | 318 _notifyServerState(serverAddress.toString()); |
| 317 onServerAddressChange('$serverAddress'); | 319 onServerAddressChange('$serverAddress'); |
| 318 return this; | 320 return this; |
| 319 }).catchError((e, st) { | 321 } catch (e, st) { |
| 320 print('Could not start Observatory HTTP server:\n$e\n$st\n'); | 322 print('Could not start Observatory HTTP server:\n$e\n$st\n'); |
| 321 _notifyServerState(""); | 323 _notifyServerState(""); |
| 322 onServerAddressChange(null); | 324 onServerAddressChange(null); |
| 323 return this; | 325 return this; |
| 324 }); | 326 } |
| 325 } | 327 } |
| 326 | 328 |
| 327 Future cleanup(bool force) { | 329 Future cleanup(bool force) { |
| 328 if (_server == null) { | 330 if (_server == null) { |
| 329 return new Future.value(null); | 331 return new Future.value(null); |
| 330 } | 332 } |
| 331 return _server.close(force: force); | 333 return _server.close(force: force); |
| 332 } | 334 } |
| 333 | 335 |
| 334 Future shutdown(bool forced) { | 336 Future shutdown(bool forced) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 351 _notifyServerState(""); | 353 _notifyServerState(""); |
| 352 onServerAddressChange(null); | 354 onServerAddressChange(null); |
| 353 return this; | 355 return this; |
| 354 }); | 356 }); |
| 355 } | 357 } |
| 356 | 358 |
| 357 } | 359 } |
| 358 | 360 |
| 359 void _notifyServerState(String uri) | 361 void _notifyServerState(String uri) |
| 360 native "VMServiceIO_NotifyServerState"; | 362 native "VMServiceIO_NotifyServerState"; |
| OLD | NEW |