buildServerAddress function

Uri buildServerAddress(
  1. Uri uri,
  2. bool secure, {
  3. bool webSockets = true,
})

Implementation

Uri buildServerAddress(Uri uri, bool secure, {bool webSockets = true}) {
  // handle plain host without scheme: treat single-segment path as host
  if (uri.host.isEmpty && uri.pathSegments.length == 1) {
    uri = uri.replace(
      host: uri.pathSegments.first,
      pathSegments: uri.pathSegments.skip(1).toList(),
    );
  }
  uri = uri.replace(scheme: (webSockets ? 'ws' : 'http') + (secure ? 's' : ''));
  if (!uri.hasPort) {
    uri = uri.replace(port: kDefaultPort);
  }
  return uri;
}