canonicalAuthenticationOrigin function
String
canonicalAuthenticationOrigin( - Uri address
)
Implementation
String canonicalAuthenticationOrigin(Uri address) {
final scheme = switch (address.scheme.toLowerCase()) {
'https' => 'wss',
'http' => 'ws',
'wss' => 'wss',
'ws' => 'ws',
_ => throw ArgumentError.value(
address,
'address',
'Authentication origins must use WS or WSS.',
),
};
var host = address.host.toLowerCase();
if (host.endsWith('.')) host = host.substring(0, host.length - 1);
if (host.isEmpty) {
throw ArgumentError.value(address, 'address', 'Host cannot be empty.');
}
final port = address.hasPort ? address.port : (scheme == 'wss' ? 443 : 80);
return Uri(scheme: scheme, host: host, port: port).toString();
}