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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 if ((uri.port == _server.port) && | 159 if ((uri.port == _server.port) && |
160 ((uri.host == _server.address.address) || | 160 ((uri.host == _server.address.address) || |
161 (uri.host == _server.address.host))) { | 161 (uri.host == _server.address.host))) { |
162 return true; | 162 return true; |
163 } | 163 } |
164 | 164 |
165 return false; | 165 return false; |
166 } | 166 } |
167 | 167 |
168 bool _originCheck(HttpRequest request) { | 168 bool _originCheck(HttpRequest request) { |
169 if (_originCheckDisabled) { | 169 if (_originCheckDisabled || Platform.isFuchsia) { |
170 // Always allow. | 170 // Always allow. |
171 return true; | 171 return true; |
172 } | 172 } |
173 // First check the web-socket specific origin. | 173 // First check the web-socket specific origin. |
174 List<String> origins = request.headers["Sec-WebSocket-Origin"]; | 174 List<String> origins = request.headers["Sec-WebSocket-Origin"]; |
175 if (origins == null) { | 175 if (origins == null) { |
176 // Fall back to the general Origin field. | 176 // Fall back to the general Origin field. |
177 origins = request.headers["Origin"]; | 177 origins = request.headers["Origin"]; |
178 } | 178 } |
179 if (origins == null) { | 179 if (origins == null) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 } | 299 } |
300 | 300 |
301 Future startup() async { | 301 Future startup() async { |
302 if (_server != null) { | 302 if (_server != null) { |
303 // Already running. | 303 // Already running. |
304 return this; | 304 return this; |
305 } | 305 } |
306 | 306 |
307 // Startup HTTP server. | 307 // Startup HTTP server. |
308 try { | 308 try { |
309 var addresses = await InternetAddress.lookup(_ip); | |
310 var address; | 309 var address; |
311 // Prefer IPv4 addresses. | 310 if (Platform.isFuchsia) { |
312 for (var i = 0; i < addresses.length; i++) { | 311 address = InternetAddress.ANY_IP_V6; |
siva
2017/01/13 18:33:00
Will this also work for clients that only have IPv
zra
2017/01/13 20:25:57
Yes, I have verified that I can connect from my de
| |
313 address = addresses[i]; | 312 } else { |
314 if (address.type == InternetAddressType.IP_V4) break; | 313 var addresses = await InternetAddress.lookup(_ip); |
314 // Prefer IPv4 addresses. | |
315 for (var i = 0; i < addresses.length; i++) { | |
316 address = addresses[i]; | |
317 if (address.type == InternetAddressType.IP_V4) break; | |
318 } | |
315 } | 319 } |
316 _server = await HttpServer.bind(address, _port); | 320 _server = await HttpServer.bind(address, _port); |
317 _server.listen(_requestHandler, cancelOnError: true); | 321 _server.listen(_requestHandler, cancelOnError: true); |
318 print('Observatory listening on $serverAddress'); | 322 print('Observatory listening on $serverAddress'); |
319 // Server is up and running. | 323 // Server is up and running. |
320 _notifyServerState(serverAddress.toString()); | 324 _notifyServerState(serverAddress.toString()); |
321 onServerAddressChange('$serverAddress'); | 325 onServerAddressChange('$serverAddress'); |
322 return this; | 326 return this; |
323 } catch (e, st) { | 327 } catch (e, st) { |
324 print('Could not start Observatory HTTP server:\n$e\n$st\n'); | 328 print('Could not start Observatory HTTP server:\n$e\n$st\n'); |
(...skipping 30 matching lines...) Expand all Loading... | |
355 _notifyServerState(""); | 359 _notifyServerState(""); |
356 onServerAddressChange(null); | 360 onServerAddressChange(null); |
357 return this; | 361 return this; |
358 }); | 362 }); |
359 } | 363 } |
360 | 364 |
361 } | 365 } |
362 | 366 |
363 void _notifyServerState(String uri) | 367 void _notifyServerState(String uri) |
364 native "VMServiceIO_NotifyServerState"; | 368 native "VMServiceIO_NotifyServerState"; |
OLD | NEW |