url property Null safety

Uri url

The URL of the server.

Requests to this URL or any URL beneath it are handled by the handler passed to mount. If mount hasn't yet been called, the requests wait until it is. If close has been called, the handler will not be invoked; otherwise, the behavior is implementation-dependent.


Uri get url {
  if (server.address.isLoopback) {
    return Uri(scheme: 'http', host: 'localhost', port: server.port);

  // IPv6 addresses in URLs need to be enclosed in square brackets to avoid
  // URL ambiguity with the ":" in the address.
  if (server.address.type == InternetAddressType.IPv6) {
    return Uri(
        scheme: 'http',
        host: '[${server.address.address}]',
        port: server.port);

  return Uri(scheme: 'http', host: server.address.address, port: server.port);