HttpAgent constructor
HttpAgent({
- HttpAgentOptions? options,
- String defaultProtocol = 'https',
- String defaultHost = 'localhost',
- int 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(options.identity ?? const AnonymousIdentity());
/// setCredential
if (options.credentials != null) {
final name = options.credentials?.name ?? '';
final password = options.credentials?.password;
setCredentials("$name${password != null ? ':$password' : ''}");
} else {
setCredentials('');
}
_baseHeaders = _createBaseHeaders();
} else {
setIdentity(const AnonymousIdentity());
setHost('$defaultProtocol://$defaultHost:$defaultPort');
setFetch(_defaultFetch);
setCredentials('');
// run default headers
_baseHeaders = _createBaseHeaders();
}
}