HttpRequester constructor
HttpRequester(])
Implementation
HttpRequester(
Map<String, Object?> config, [
Map<String, Object?>? properties,
this.httpCache,
]) : config = _asMapProperties(config),
properties = _asMapProperties(properties) {
var config = this.config;
var schemeType = config.findPropertyAsStringTrimLC([
'scheme',
'protocol',
'type',
], 'http')!;
var secure = config.findPropertyAsBool(['secure', 'ssl', 'https'], false)!;
var host = config.getPropertyAsStringTrimLC('host');
var method = config.findPropertyAsStringTrimLC([
'method',
'http_method',
'httpMethod',
]);
var path = config.getPropertyAsString('path', '/');
var parameters = config.getPropertyAsStringMap('parameters');
var bodyType = config.findPropertyAsStringTrimLC([
'body_type',
'bodyType',
'content_type',
'content-type',
'contentType',
]);
// Not lower-cased (as the other properties): the body content as is.
var body = config.getPropertyAsStringTrim('body');
var responseType = config.findPropertyAsStringTrimLC([
'response_type',
'responseType',
]);
if (responseType != null) responseType = responseType.toLowerCase();
var runtimeUri = getHttpClientRuntimeUri();
var scheme = schemeType == 'https'
? 'https'
: (schemeType == 'http' ? 'http' : runtimeUri.scheme);
if (secure) {
scheme = 'https';
}
if (host == null) {
host = '${runtimeUri.host}:${runtimeUri.port}';
} else if (RegExp(r'^:?\d+$').hasMatch(host)) {
var port = host;
if (port.startsWith(':')) port = port.substring(1);
host = '${runtimeUri.host}:$port';
}
var httpMethod = getHttpMethod(method, HttpMethod.GET)!;
var pathBuilt = '/';
if (path != null) {
pathBuilt = path.contains('{{')
? buildStringPattern(path, this.properties.toStringProperties()) ??
path
: path;
}
String? bodyBuilt;
if (body != null) {
bodyBuilt = body.contains('{{')
? buildStringPattern(body, this.properties.toStringProperties())
: body;
}
_host = host;
_scheme = scheme;
_httpMethod = httpMethod;
_path = pathBuilt;
_parameters = parameters;
_responseType = responseType;
_bodyType = bodyType;
_body = bodyBuilt;
}