| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 close(); | 89 close(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void post(dynamic result) { | 92 void post(dynamic result) { |
| 93 if (result == null) { | 93 if (result == null) { |
| 94 close(); | 94 close(); |
| 95 return; | 95 return; |
| 96 } | 96 } |
| 97 HttpResponse response = request.response; | 97 HttpResponse response = request.response; |
| 98 response.headers.contentType = jsonContentType; | 98 response.headers.contentType = jsonContentType; |
| 99 final uri = Uri.parse(request.headers['Origin'].single ?? ''); | 99 final origins = request.headers['Origin']; |
| 100 final noPortOrigin = new Uri(host: uri.host, scheme: uri.scheme).origin; | 100 if ((origins != null) && (origins.isNotEmpty)) { |
| 101 if (_allowedOrigins.contains(noPortOrigin)) { | 101 final uri = Uri.parse(origins.first); |
| 102 response.headers.add('Access-Control-Allow-Origin', uri.origin); | 102 final noPortOrigin = new Uri(host: uri.host, scheme: uri.scheme).origin; |
| 103 if (_allowedOrigins.contains(noPortOrigin)) { |
| 104 response.headers.add('Access-Control-Allow-Origin', uri.origin); |
| 105 } |
| 103 } | 106 } |
| 104 if (result is String) { | 107 if (result is String) { |
| 105 response.write(result); | 108 response.write(result); |
| 106 } else { | 109 } else { |
| 107 assert(result is List); | 110 assert(result is List); |
| 108 Uint8List cstring = result[0]; // Already in UTF-8. | 111 Uint8List cstring = result[0]; // Already in UTF-8. |
| 109 response.add(cstring); | 112 response.add(cstring); |
| 110 } | 113 } |
| 111 response.close(); | 114 response.close(); |
| 112 close(); | 115 close(); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 _notifyServerState("", 0); | 329 _notifyServerState("", 0); |
| 327 onServerAddressChange(null); | 330 onServerAddressChange(null); |
| 328 return this; | 331 return this; |
| 329 }); | 332 }); |
| 330 } | 333 } |
| 331 | 334 |
| 332 } | 335 } |
| 333 | 336 |
| 334 void _notifyServerState(String ip, int port) | 337 void _notifyServerState(String ip, int port) |
| 335 native "VMServiceIO_NotifyServerState"; | 338 native "VMServiceIO_NotifyServerState"; |
| OLD | NEW |