buildServerAddress function
Uri
buildServerAddress( - Uri uri,
- bool secure, {
- bool webSockets = true,
})
Implementation
Uri buildServerAddress(Uri uri, bool secure, {bool webSockets = true}) {
// Uri.parse treats host:port as a scheme and a path. Parse it as an
// authority so ports, paths and query parameters keep their meaning.
if (!uri.hasAuthority) {
uri = Uri.parse('//${uri.toString()}');
}
if (uri.host.isEmpty) {
throw const FormatException('A server address must include a host.');
}
uri = uri.replace(scheme: (webSockets ? 'ws' : 'http') + (secure ? 's' : ''));
if (!uri.hasPort) {
uri = uri.replace(port: kDefaultPort);
}
return uri;
}