buildRequestHeaders method
Map<String, String>
buildRequestHeaders(
- HttpClient client,
- HttpMethod method,
- String url, {
- Map<
String, String> ? headers, - Authorization? authorization,
- String? contentType,
- String? accept,
Helper to build the request headers.
Implementation
Map<String, String> buildRequestHeaders(
HttpClient client,
HttpMethod method,
String url, {
Map<String, String>? headers,
Authorization? authorization,
String? contentType,
String? accept,
}) {
var requestHeaders = client.buildRequestHeaders(url) ?? <String, String>{};
if (contentType != null && method != HttpMethod.GET) {
requestHeaders[HttpRequest._headerKeyContentType] = contentType;
}
if (accept != null) {
requestHeaders['Accept'] = accept;
}
if (authorization != null && authorization.usesAuthorizationHeader) {
var credential = authorization.resolvedCredential!;
var authorizationHeaderLine = credential.buildAuthorizationHeaderLine();
if (authorizationHeaderLine != null) {
requestHeaders['Authorization'] = authorizationHeaderLine;
}
}
if (headers != null) {
requestHeaders.addAll(headers);
}
return requestHeaders;
}