in core.ts [428:466]
private buildHeaders({
options,
headers,
contentLength,
retryCount,
}: {
options: FinalRequestOptions;
headers: Record<string, string | null | undefined>;
contentLength: string | null | undefined;
retryCount: number;
}): Record<string, string> {
const reqHeaders: Record<string, string> = {};
if (contentLength) {
reqHeaders["content-length"] = contentLength;
}
const defaultHeaders = this.defaultHeaders(options);
applyHeadersMut(reqHeaders, defaultHeaders);
applyHeadersMut(reqHeaders, headers);
// let builtin fetch set the Content-Type for multipart bodies
if (isMultipartBody(options.body) && shimsKind !== "node") {
delete reqHeaders["content-type"];
}
// Don't set the retry count header if it was already set or removed through default headers or by the
// caller. We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to
// account for the removal case.
if (
getHeader(defaultHeaders, "x-stainless-retry-count") === undefined &&
getHeader(headers, "x-stainless-retry-count") === undefined
) {
reqHeaders["x-stainless-retry-count"] = String(retryCount);
}
this.validateHeaders(reqHeaders, headers);
return reqHeaders;
}