dart-sdk/pkg/vm_service/lib/utils.dart
Ben Konyi fb5ffc8275 [ package:vm_service] Output null-safe code from package:vm_service code generator
TEST=Existing VM service tests

Change-Id: Ia3877927f8c761c8f37a37f1efe87221cc1ac2aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/156980
Reviewed-by: Gary Roumanis <grouma@google.com>
2021-01-08 21:19:38 +00:00

21 lines
861 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.
/// 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);
}