/**
 * Prepares headers list to be sent to the remote machine.
 * If `defaultHeaders` option is set then it adds `user-agent` and `accept`
 * headers.
 */
export function prepareHeaders(headers, context, withPayload = false) {
    const { defaultHeaders, defaultUserAgent, defaultAccept, request } = context;
    if (defaultHeaders) {
        if (!headers.has('user-agent')) {
            if (defaultUserAgent) {
                headers.set('user-agent', defaultUserAgent);
            }
            else {
                headers.set('user-agent', 'api client');
            }
        }
        if (!headers.has('accept')) {
            if (defaultAccept) {
                headers.set('accept', defaultAccept);
            }
            else {
                headers.set('accept', '*/*');
            }
        }
    }
    if (withPayload) {
        if (!headers.has('content-type') && request.payloadOptions) {
            if (request.payloadOptions.mime) {
                headers.set('content-type', request.payloadOptions.mime);
            }
        }
    }
}
/**
 * Generate proxy authorization header
 */
export function generateProxyAuthHeader(context) {
    const { hasProxy, isProxyTunnel, proxyUsername, proxyPassword, proxyAuthorization } = context;
    if (!hasProxy || isProxyTunnel) {
        return undefined;
    }
    if (proxyAuthorization) {
        return proxyAuthorization;
    }
    if (proxyUsername && proxyPassword) {
        const auth = `${proxyUsername}:${proxyPassword}`;
        return `Basic ${Buffer.from(auth).toString('base64')}`;
    }
    return undefined;
}
//# sourceMappingURL=MessageProcessor.js.map