dart-sdk/pkg/vm_service/lib/utils.dart
Ben Konyi 368b3f0ab4 Reland "[ VM / Service ] Pulled in vm_service_drivers from its own repo."
Changes from original CL:
 * Removed service_undocumented.md
 * Removed generation of wrappers for undocumented RPCs
 * Cleaned up generation code which was used for generating wrappers for undocumented RPCs
 * Removed JARs from pkg/vm_service/java/third_party

This reverts commit 477a3c4748.

Change-Id: I8d36733c8b2602e4935c3f23698d3f7c97a20187
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110135
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2019-07-25 18:46:43 +00:00

23 lines
896 B
Dart

// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:meta/meta.dart';
/// Map the URI to a WebSocket URI for the VM service protocol.
///
/// If the URI is already a VM Service WebSocket URI it will not be modified.
Uri convertToWebSocketUrl({@required Uri serviceProtocolUrl}) {
final isSecure = serviceProtocolUrl.isScheme('wss') ||
serviceProtocolUrl.isScheme('https');
final scheme = isSecure ? 'wss' : 'ws';
final path = serviceProtocolUrl.path.endsWith('/ws')
? serviceProtocolUrl.path
: (serviceProtocolUrl.path.endsWith('/')
? '${serviceProtocolUrl.path}ws'
: '${serviceProtocolUrl.path}/ws');
return serviceProtocolUrl.replace(scheme: scheme, path: path);
}