HttpAgent constructor

HttpAgent({
  1. HttpAgentOptions? options,
  2. String defaultProtocol = 'https',
  3. String defaultHost = 'localhost',
  4. String defaultPort = ':8000',
})

Implementation

HttpAgent(
    {HttpAgentOptions? options,
    this.defaultProtocol = 'https',
    this.defaultHost = 'localhost',
    this.defaultPort = ':8000'}) {
  if (options != null) {
    if (options.source is HttpAgent && options.source != null) {
      setPipeline(options.source!._pipeline);
      setIdentity(options.source!._identity);
      setHost(options.source!._host);
      setCredentials(options.source!._credentials);
      setFetch(options.source!._fetch);
    } else {
      setFetch(_defaultFetch);
    }

    /// setHost
    if (options.host != null) {
      setHost(defaultProtocol + '://${options.host}');
    } else {
      setHost(defaultProtocol + '://$defaultHost$defaultPort');
    }

    /// setIdentity
    setIdentity(Future.value(options.identity ?? AnonymousIdentity()));

    /// setCrendential
    if (options.credentials != null) {
      var name = options.credentials?.name ?? '';
      var password = options.credentials?.password;
      setCredentials("$name${password != null ? ':' + password : ''}");
    } else {
      setCredentials("");
    }

    _baseHeaders = _createBaseHeaders();
  } else {
    setIdentity(Future.value(AnonymousIdentity()));
    setHost(defaultProtocol + '://$defaultHost$defaultPort');
    setFetch(_defaultFetch);
    setCredentials("");
    // run default headers
    _baseHeaders = _createBaseHeaders();
  }
}