bind static method

Future<DartIoGitHttpServer> bind({
  1. required GitSmartHttpHandler handler,
  2. required FutureOr<GitPrincipal?> authenticate(
    1. HttpRequest request
    ),
  3. InternetAddress? address,
  4. int port = 0,
  5. bool shared = false,
})

Binds a server on address and port, and starts answering smart HTTP requests with handler.

address defaults to the loopback address and port to 0, which lets the operating system choose a free port; read it from port. shared asks the operating system to allow several servers on the same port.

authenticate is called for every request, before the handler runs, and returns the identity the host authenticated, or null for an anonymous request.

Implementation

static Future<DartIoGitHttpServer> bind({
  required GitSmartHttpHandler handler,
  required FutureOr<GitPrincipal?> Function(HttpRequest request) authenticate,
  InternetAddress? address,
  int port = 0,
  bool shared = false,
}) async {
  final HttpServer server = await HttpServer.bind(
    address ?? InternetAddress.loopbackIPv4,
    port,
    shared: shared,
  );
  return DartIoGitHttpServer._(
    server,
    DartIoExchange<_DartIoGitHttpRequest>(
      handler: handler,
      authenticate: (_DartIoGitHttpRequest request) =>
          authenticate(request.raw),
    ),
  );
}