checkBinder static method

void checkBinder(
  1. ServerAdapter? server,
  2. AppConfig config
)

Throws an ArgumentError when server is a CustomServer and config asks for tls or http2, on the main port or on a port of AppConfig.ports. Its binder sets them on its own server. It also throws for BuiltInServer.ioHttpServer with http2: dart:io has no HTTP/2.

Implementation

static void checkBinder(ServerAdapter? server, AppConfig config) {
  bool tls = config.tls != null;
  bool http2 = config.http2;
  for (PortConfig port in config.ports) {
    tls = tls || port.tls != null;
    http2 = http2 || port.http2;
  }
  // the built-in one only: a subclass (eg. a CustomServer) binds its own
  if (server.runtimeType == IoServerAdapter && http2) {
    throw ArgumentError(
      'The dart:io server (BuiltInServer.ioHttpServer) has no HTTP/2. '
          'Remove AppConfig.http2 and PortConfig.http2, or use the native '
          'server',
      'http2',
    );
  }
  if (ServerAdapters.builtIn(server) != null) return;
  if (tls) {
    throw ArgumentError(
      'AppConfig.tls and PortConfig.tls are for the built-in servers. '
          'With a CustomServer, set TLS on the server in the binder',
      'tls',
    );
  }
  if (http2) {
    throw ArgumentError(
      'AppConfig.http2 and PortConfig.http2 are for the built-in servers. '
          'With a CustomServer, set HTTP/2 on the server in the binder',
      'http2',
    );
  }
}