getAuthString method
Implementation
String getAuthString(HttpRequestModel res) {
final cnonce = _computeNonce();
final url = Uri.parse(res.url);
final method = res.method.name.toUpperCase();
final body = res.body ?? '';
_nc += 1;
// if url has query parameters, append query to path
final path = url.hasQuery ? '${url.path}?${url.query}' : url.path;
// after the first request we have the nonce, so we can provide credentials
final authValues = computeResponse(
method,
path,
body,
_algorithm,
_qop,
_opaque,
_realm!,
cnonce,
_nonce,
_nc,
username,
password,
);
final authValuesString = authValues.entries
.where((e) => e.value != null)
.map(
(e) => [
e.key,
'=',
['algorithm', 'qop', 'nc'].contains(e.key) ? '' : '"',
e.value,
['algorithm', 'qop', 'nc'].contains(e.key) ? '' : '"',
].join(''),
)
.toList()
.join(', ');
final authString = 'Digest $authValuesString';
return authString;
}