allowedBundleOrigin function

String allowedBundleOrigin(
  1. String url, {
  2. String? apiBaseUrl,
})

The normalized origin (scheme://host[:port]) of url when a skin bundle may load from it, else "". A bundle is allowed over https, or over http only when its origin equals the origin of apiBaseUrl (the Test Kit mock serves skins from its own origin). Scheme and host compare case-insensitively; a default port is dropped. Never throws. Port of Android allowedBundleOrigin.

Implementation

String allowedBundleOrigin(String url, {String? apiBaseUrl}) {
  final origin = _normalizedOrigin(url);
  if (origin == null) return '';
  if (origin.startsWith('https://')) return origin;
  if (origin.startsWith('http://') &&
      apiBaseUrl != null &&
      origin == _normalizedOrigin(apiBaseUrl)) {
    return origin;
  }
  return '';
}