httpEndpointURL function

String httpEndpointURL(
  1. String socketUrl
)

Converts a WebSocket URL to an HTTP URL.

Implementation

String httpEndpointURL(String socketUrl) {
  var url = socketUrl;

  // Replace 'ws' or 'wss' with 'http' or 'https' respectively
  url = url.replaceFirst(RegExp(r'^ws', caseSensitive: false), 'http');

  // Remove WebSocket-specific endings
  url = url.replaceFirst(
    RegExp(r'(/socket/websocket|/socket|/websocket)/?$', caseSensitive: false),
    '',
  );

  // Remove trailing slashes
  return url.replaceAll(RegExp(r'/+$'), '');
}