validatePublicOrigin static method

Uri validatePublicOrigin(
  1. Uri value
)

Validates and canonicalizes a fixed HTTP(S) deployment origin.

Factories may call this before acquiring database or other resources.

Implementation

static Uri validatePublicOrigin(Uri value) {
  if ((value.scheme != 'http' && value.scheme != 'https') ||
      !value.hasAuthority ||
      value.host.isEmpty ||
      value.userInfo.isNotEmpty ||
      (value.path.isNotEmpty && value.path != '/') ||
      value.hasQuery ||
      value.hasFragment ||
      value.port < 1 ||
      value.port > 65535) {
    throw ArgumentError.value(
      value,
      'publicOrigin',
      'Must be an absolute HTTP(S) origin without credentials, path, query, or fragment.',
    );
  }
  return Uri.parse(value.origin);
}