normalizeHttpUri function

Uri? normalizeHttpUri(
  1. String raw
)

规范化 http(s) URI;无 scheme 时补 https://。

Implementation

Uri? normalizeHttpUri(String raw) {
  var text = raw.trim();
  if (text.isEmpty) return null;
  if (!text.contains('://')) {
    text = 'https://$text';
  }
  final uri = Uri.tryParse(text);
  if (uri == null) return null;
  if (uri.scheme != 'http' && uri.scheme != 'https') return null;
  return uri;
}